影片內容說明兩者最大差異在於 ref 參數必須先初始化,而 out 參數不需要
MVA 範例:說明 ref 和 out 都是 ByRef
static void Main(string[] args) { string outString = "This is the original outString"; Console.WriteLine(outString); outMethod(out outString); Console.WriteLine(outString); string refString = "This is the original ref string"; Console.WriteLine(refString); refMethod(ref refString); Console.WriteLine(refString); } static void outMethod(out string outString) { outString = "This is the new outString value"; } static void refMethod(ref string refString) { refString = "This is the new refString value"; }
沒有留言:
張貼留言