Data Types in C#
C# provides various built-in data types. Built-in data types are predefined data types that can be directly used in a program to declare variables.
Built-in #Bytes Values
Data Type
Char 2 0 to 65535
Int 4 -2,147,483,648 to 2,147,483,647
Float 4 -3.402823E+38 to -1.401298E-45 (for negative values)
1.401298E-45 to 3.402823E+38 (for positive values)
Double 8 -1.79769313486232E308 to -4.94065645841247E-
324 (for negative values) and 4.94065645841247E-
324 to 1.79769313486232E308 (for positive values)
Bool 1 True or False
String Variable 0-2 billion Unicode characters
length
The #Bytes column in the preceding table specifies the bytes that are required to store the variable in the memory. The Values column specifies the range of values that can be stored in the variable.
Types of Data Types
C# supports the following data types:- Value types: The value types directly contain data. Some examples of value types are char, int, and float, which can be used for storing alphabets, integers, and floating point values, respectively. When you declare an int variable, the system allocates memory to store the value. The following figure shows the memory allocation of an int variable.
- Reference types: The reference type variables, instead of containing data, contain a reference (address) to the data stored in the memory.More than one reference type variable can be created to refer to the same memory location. This means that if the value in the referenced memory location is modified, all the referring variables automatically reflect the changed value. The example of a reference type is the string data type. The following figure shows the memory allocation of a string value HELLO in a variable named Str.