4
Reply

What is difference between an reference type and value type in C#?

Rohan  Rathore

Rohan Rathore

11y
2k
0
Reply

    Value Type Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. Some examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively. When you declare an int type, the system allocates memory to store the value.reference types The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.In other words, they refer to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value. Example of built-in reference types are: object, dynamic, and string.Credit:- http://tech.queryhome.com/149219/data-types-what-difference-between-value-type-reference-types

    Value Type Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. Some examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively. When you declare an int type, the system allocates memory to store the value.reference types The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.In other words, they refer to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value. Example of built-in reference types are: object, dynamic, and string.Credit:- http://tech.queryhome.com/149219/data-types-what-difference-between-value-type-reference-types

    Value Type Value type variables can be assigned a value directly. They are derived from the class System.ValueType. The value types directly contain data. Some examples are int, char, and float, which stores numbers, alphabets, and floating point numbers, respectively. When you declare an int type, the system allocates memory to store the value.reference types The reference types do not contain the actual data stored in a variable, but they contain a reference to the variables.In other words, they refer to a memory location. Using multiple variables, the reference types can refer to a memory location. If the data in the memory location is changed by one of the variables, the other variable automatically reflects this change in value. Example of built-in reference types are: object, dynamic, and string.Credit:- http://tech.queryhome.com/149219/data-types-what-difference-between-value-type-reference-types

    Reference type the kind of datatypes whose values are stored in heap memory but the reference variable is present in stack memory having the addresses location of the corresponding value present inside Heap. All the userdefine datatypes like classes,delegates etc will come in this categoryWhile value type are the kind the of the datatypes whose value and reference variable is present inside the stack memory. All the primitive types in c# are usually comes in value types. for learning more about c# You can prefer this Link. c# interview questions