C# Value and Reference types

前端 未结 6 1227
灰色年华
灰色年华 2021-01-06 15:55

Please see the following lines of code mentioned below:

byte[] a = { 1, 2, 3, 4 };
byte[] b = a; // b will have all values of a.
a = null; 

6条回答
  •  醉梦人生
    2021-01-06 16:24

    A reference type variable points to a value. When you assign one ref type variable to another you copy reference to its value not to the variable itself. This is why b still points to a table of values.

提交回复
热议问题