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.
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |