C# DataTypes

Data Types in a programming language describes that what type of data a variable can hold . CSharp is a strongly typed language, therefore every variable and object must have a declared type. The CSharp type system contains three Type categories. They are Value Types , Reference Types and Pointer Types . In CSharp it is possible to convert a value of one type into a value of another type . The operation of Converting a Value Type to a Reference Type is called Boxing and the reverse operation is called Unboxing .

When we declare a variable, we have to tell the compiler about what type of the data the variable can hold or which data type the variable belongs to.


  1. DataType : The type of data that the variable can hold
  2. VariableName : the variable we declare for hold the values.


  1. int : is the data type
  2. count : is the variable name

The above example shows , declare a variable 'count' for holding an integer values.

The following are the commonly using datatypes in C# .


The bool keyword is an alias of System.Boolean. It is used to declare variables to store the Boolean values, true and false. In C# , there is no conversion between the bool type and other types.

  1. C# Runtime type : System.Boolean
  2. CSharp declaration : bool flag;
  3. CSharp Initialization : flag = true;
  4. CSharp default initialization value : false


int variables are stored signed 32 bit integer values in the range of -2,147,483,648 to +2,147,483,647

  1. C# Runtime type : System.Int32
  2. CSharp declaration : int count;
  3. CSharp Initialization : count = 100;
  4. CSharp default initialization value : 0


The decimal keyword denotes a 128-bit data type.The approximate range and precision for the decimal type are -1.0 X 10-28 to 7.9 X 1028

  1. C# Runtime type : System.Decimal
  2. CSharp declaration : decimal val;
  3. CSharp Initialization : val = 0.12;
  4. CSharp default initialization value : 0.0M


The string type represents a string of Unicode characters. string variables are stored any number of alphabetic,

numerical, and special characters .

  1. C# Runtime type : System.String
  2. CSharp declaration : string str;
  3. CSharp Initialization : str = "csharp string"; (C) 2021    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.
SiteMap  | Terms  | About