change field value in a method
using System;
public class Foo
{
public int i;
}
class RefTest2App
{
public static void ChangeValue(Foo f)
{
f.i = 42;
}
static void Main(string[] args)
{
Foo test = new Foo();
test.i = 6;
Console.WriteLine("BEFORE METHOD CALL");
Console.WriteLine("test.i={0}", test.i);
Console.WriteLine();
ChangeValue(test);
Console.WriteLine("AFTER METHOD CALL");
Console.WriteLine("test.i={0}", test.i);
}
}
Related examples in the same category