Question:What are value and reference types? 

Answer Value type: The content of a value type variable or constant is simply a value. For example, the content of the built-in value type, int, is 32 bits of data. Its contents in memory is allocated on the stack. We can define a custom value type with the 'struct' keyword.
public struct Point { public int X, Y; }
Reference type: A reference type has two parts: an object and the reference to that object. The content of a reference-type variable or constant is a reference to an object that contains the value. A reference type, such as an instance of a class or an array, is allocated in a different area of memory called the heap. We use 'class' keyword to define it.
public class Point { public int X, Y; }
 

+ Report
Total Preview: 1027
What are value and reference types?
Copyright © 2024. Powered by Intellect Software Ltd