Tutorial by Examples

public static void Main(string[] args) { var studentList = new List<Student>(); studentList.Add(new Student("Scott", "Nuke")); studentList.Add(new Student("Vincent", "King")); studentList.Add(new Student("Craig", "Be...
If you want the Value Types vs Reference Types in methods example to work properly, use the ref keyword in your method signature for the parameter you want to pass by reference, as well as when you call the method. public static void Main(string[] args) { ... DoubleNumber(ref number); ...
From the documentation : In C#, arguments can be passed to parameters either by value or by reference. Passing by reference enables function members, methods, properties, indexers, operators, and constructors to change the value of the parameters and have that change persist in the calling e...
var a = new List<int>(); var b = a; a.Add(5); Console.WriteLine(a.Count); // prints 1 Console.WriteLine(b.Count); // prints 1 as well Assigning to a variable of a List<int> does not create a copy of the List<int>. Instead, it copies the reference to the List<int>. We ...
There are two possible ways to pass a value type by reference: ref and out. The difference is that by passing it with ref the value must be initialized but not when passing it with out. Using out ensures that the variable has a value after the method call: public void ByRef(ref int value) { C...
Code class Program { static void Main(string[] args) { int a = 20; Console.WriteLine("Inside Main - Before Callee: a = {0}", a); Callee(a); Console.WriteLine("Inside Main - After Callee: a = {0}", a); Console.WriteLine(); ...

Page 1 of 1