using System;
namespace struct_by_ref_and_out
{
struct Test
{
public int x;
}
class Class1
{
static void ChangeVal(Test t)
{
t.x = 400;
}
static void ChangeRef(ref Test t)
{
t.x = 100;
}
static void ChangeOut(out Test t)
{
t.x = 255;
}
static void Main(string[] args)
{
Test t_val = new Test();
t_val.x = 7;
ChangeVal(t_val);
Console.WriteLine("by val t_val.x = {0}", t_val.x); // by val t_val.x = 7
Test t_ref = new Test();
t_ref.x = 7;
ChangeRef(ref t_ref);
Console.WriteLine("by ref t_ref.x = {0}", t_ref.x); // by ref t_ref.x = 100
Test t_out = new Test();
ChangeOut(out t_out);
Console.WriteLine("by out t_out.x = {0}", t_out.x); // by out t_out.x = 255
}
}
}