Essential C# Value type vs Reference type  Suggest an edit

Passing by reference

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); // calling code
    Console.WriteLine(number); // outputs 8
public void DoubleNumber(ref int number)
    number += number;

Making these changes would make the number update as expected, meaning the console output for number would be 8.

Table Of Contents
22 Enum
31 Value type vs Reference type
107 Stream
108 Timers
  ↑ ↓ to navigate     ↵ to select     Esc to close