|
C# 2008 Programmer's ReferenceThe first output will be: OK OK When you change btn2's Text property to "Cancel", you invariably change btn1's Text property, as the second output shows: Cancel Cancel That's because btn1 and btn2 are both pointing to the same Button object. They both contain a reference to that object instead of storing the value of the object. The declaration statement (Button btn1, btn2;) simply creates two variables that contain references to Button objects (in the example these two variables point to the same object). To remove the reference to an object in a reference type, simply use the null keyword: btn2 = null; When a reference type is set to null, attempting to access its members results in a runtime error. Value Types versus Reference Types For any discussion about value types and reference types, it is important to understand how the .NET Framework manages the data in memory. Basically, the memory is divided into two parts — the stack and the heap. The stack is a data structure used to store value-type variables ...» | Код для вставки книги в блог HTML
phpBB
текст
|
|