C# - C Sharp: ref và out
Giải phóng thời gian, khai phóng năng lực
using System; namespace ConsoleApp2 { class Bai4 { static void NhapLieu(out int a) { Console.Write("Input a: "); Int32.TryParse(Console.ReadLine(), out a); } static void Input(ref float b) { Console.Write("Input b: "); b = Single.Parse(Console.ReadLine()); } static void Main(string[] args) { //Từ khóa ref và out: Liên quan đến vấn đề con trỏ. //Cho phép truyền đi địa chỉ của biến tới hàm (phương thức khác). int a; float b = 0; NhapLieu(out a); Console.WriteLine("a=" + a); Input(ref b); } } }
Giải phóng thời gian, khai phóng năng lực