.NET Programming - C# DataTypes

For Programming using C# ,  the following datatypes are used. All the data types in .net framework are available within the namespace System.

 Category  Class/Structre Name Data Type in C#.NET  NO. of Bytes   Range
 Integer  System.Byte  Byte  1(Unsigned)  0 to 255
   System.SByte  Sbyte  1(Signed)  -128 to 127
   System.Int16  Short  2(Signed)  -32,768 to 32,767
   System.Uint16  Ushort  2(Unsigned)  0 to 65,535
   System.Int32  Int  4(Signed)  -2,147,483,648 to 2,147,483,647
   System.Uint32  Uint  4(Unsigned)  0 to 4,294,967,295
   System.Int64  Long  8(Signed)  -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
   System.Uint64  Ulong  8(Unsigned)  0 to 18,446,744,073,709,551,615
   Single  Float  4  ±1.5e−45 to ±3.4e38 
(Precision:7 digits)
   Double  Double  8  ±5.0e−324 to ±1.7e308
(Precision:15-16 digits)
   Decimal  Decimal  16  (-7.9 x 1028 to 7.9 x 1028) / (100 to 28)
(Precision:28-29 digits)
   Char  Char  2  
   String  String  size varies  
   DateTime  DateTime  8  
   Boolean  Bool  1  
   Object  Object  size varies  Can store any type of value
   System.IntPtr    Platform dependent  Pointer to a memory address

In the .NET framework, all the types are derived from System.Object. This relationship helps to establish common type system used throughout the .NET Framework.

Note: Of all the  C# datatypes, string and object are reference types while all other are value types.

For Implicit types in c#, please refer Var Type in C#

Optimizing Performance with .NET Datatypes

The runtime optimizes the performance of 32-bit integer types (Int32 & Uint32), so use those types for counters and other frequently accessed integer variables. For floating-point operations , Double is the most efficient type because those operations are optimized by hardware.

c# datatype c# programming language c# types of variables c# variable types data type c# programming using c# DataTypes in C#.net c# data types