Use ref to mark an object parameter : Function Parameters « Language Basics « C# / C Sharp
- C# / C Sharp
- Language Basics
- Function Parameters
Use ref to mark an object parameter
using System;
public class XInt {
public int iField = 2;
}
public class Starter {
public static void MethodA(ref XInt alias) {
XInt inner = new XInt();
inner.iField = 5;
alias = inner;
}
public static void Main() {
XInt obj = new XInt();
MethodA(ref obj);
Console.WriteLine(obj.iField); // 5
}
}
Related examples in the same category