Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0117 out parameter modifier

out is like ref modifier, but when calling the method you don't have to provide a value for the out parameter. The out parameter must have an assigned value in the method. using System; class Program { static void change(out int i) { Console.WriteLine("set the value in the change method"); i = 10; } static void Main(string[] args) { int i = 1; Console.WriteLine("before changing:" + i); change(out i); Console.WriteLine("after changing:" + i); } } The output: before changing:1 set the value in the change method after changing:10 out modifiers are often used to get value out of a method.