Essential C# Value type vs Reference type  Suggest an edit

Assignment

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 does not create a copy of the List. Instead, it copies the reference to the List. We call types that behave this way reference types.


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