VALUE TYPES AND REFERENCE TYPES OF C#

Value Types

Value types allow the whole denotive accumulation types much as “int”, added structures and enumerations. When a continuance identify is appointed to a variable, the uncertain contains that aggregation directly. If a ordinal uncertain is appointed the continuance of the first, a double of the contents is made. The digit copies crapper then be utilised independently.

This is similar to the emailing of files as attachments. A individual haw hit a word-processed writing that added individual wishes to edit. This writing crapper be emailed to the ordinal individual as an attachment. Either individual crapper today add the writing in some artefact without moving the other’s copy.

To elaborate what happens when continuance identify a uncertain is copied, study the mass diagram.

C# Value Types

In the prototypal step, the uncertain “a” is proclaimed and appointed a continuance of 72. You crapper wager this continuance decent the table of the uncertain in the prototypal column.

In the ordinal step, the uncertain “b” is proclaimed and appointed the continuance from uncertain “a”. This continuance is derived into the table of the newborn variable, as crapper be seen in the ordinal column.

In the ordinal step, the continuance in uncertain “a” is modified. The continuance in uncertain “b” is aforementioned because this uncertain contains an autarkical double of the value. The digit variables are not linked in some way.

Reference Types

Reference types allow classes of objects. When a meaning identify is appointed to a variable, the uncertain does not include the table of the goal directly. Instead, the object’s accumulation is constructed in module and the uncertain contains a meaning to that module location. If a ordinal uncertain is appointed the continuance of the first, a double of the reference is made. The digit variables today include autarkical copies of the meaning but in apiece housing the meaning points to the aforementioned data. If the properties of much an goal are changed, the add is manifest finished both references.

This is similar to the emailing of course to files. A individual haw hit a word-processed document, held in a networked folder, that added individual wishes to read. The individual crapper telecommunicate a unification to the enter to added user. Both users today hit a reference to the writing in the add of a unification to the enter in the mutual folder. Either individual haw utter the unification and add the book but the unification itself relic unchanged. If the added individual clicks her double of the link, she module wager the updated document.

To elaborate what happens when meaning identify a uncertain is copied, study the mass diagram.

C# Reference Types

In the prototypal step, the goal “a” is proclaimed as an happening of the Person class. This is a ultimate collection with a azygos concept representing the person’s peak in inches. A newborn Atlantic in memory, represented by the “X” column, is allocated to stop the object’s contents. Currently the table are invalid because the concept has not been set. The uncertain “a” holds a meaning to the module positioning “X”.

In the ordinal step, the Height concept of uncertain “a” is ordered to 72. The table of the prototypal article are unrestricted because the meaning itself has not changed. However, the module positioning retentive the peak concept is denaturized as crapper be seen in the ordinal column.

In the ordinal step, a ordinal Person uncertain “p” is proclaimed and appointed the continuance of uncertain “a”. As these are meaning types, the meaning to the “X” module positioning is derived into uncertain “b”. Both variables hit a meaning to the aforementioned inexplicit positioning and both today convey a Height concept of 72.

In the test step, the Height concept of uncertain “a” is denaturized to 75. This does not add the meaning within the variable, exclusive the table of the module retentive the property, seen in the “X” column. As both variables ease meaning that module location, both variables module convey a Height concept of 75.

Comments are closed.