Posts

Showing posts with the label #C# #valueType #ReferenceType

Value Type and Reference Type

Image
In C#, these data types are categorized based on how they store their value in the memory. C# includes the following categories of data types: Value type Reference type Pointer type Value Type A data type is a value type if it holds a data value within its own memory space. It means the variables of these data types directly contain values. For example, consider integer variable  int i = 100; The system stores 100 in the memory space allocated for the variable  i . The following image illustrates how 100 is stored at some hypothetical location in the memory (0x239110) for 'i': The following data types are all of value type: bool byte char decimal double enum float int long sbyte short struct uint ulong ushort Passing Value Type Variables When you pass a value-type variable from one method to another, the system creates a separate copy of a variable in another method. If value got changed in the one method, it wouldn't affect the variable in another method. Example: Passing ...