//out parameters need to be assigned before the parameter is passed, ref is not required.
Both out and ref parameters can change values
1 Static voidMain (string[] args)2 {3 intI =Ten;4 //int J = ten;5 //int I;6 intJ;7 //int[] K=new int[5]{1,2,3,4,5};8 int[] k =New int[5];9 //int[] L = new int[5]{1,2,3,4,5};Ten int[] L =New int[5]; One ATestClass1 TC =NewTestClass1 (); -Tc.testclass (refI); -Tc.testclass1 ( outJ); the -Tc.testclass2 ( outk); -TC.TESTCLASS3 (refl); - +Console.WriteLine ("Out I:"+I); -Console.WriteLine ("ref J:"+J); + AConsole.WriteLine ("Out k[0]:"+ k[0]); atConsole.WriteLine ("ref l[0]:"+ l[0]); - Console.read (); - } - Public voidTestClass (ref inti) - { -i = -; in } - Public voidTestClass1 ( out inti) to { +i = -; - } the Public voidTestClass2 ( out int[] k) * { $k=New int[5];Panax Notoginsengk[0] = -; - } the Public voidTESTCLASS3 (ref int[] l) + { AL =New int[5]; thel[0] = -; + } - $ $}
Out and ref difference notes in C # in the pass parameter