C# .Net – Data types

Data type:

  • In the declaration of every variable, it is mandatory to specify its data type.
  • Data type describes,
    • The size of memory allocated to variable.
    • The type of data allowed to store into variable.

Syntax: 

  • data_type  variable_name = value ;

Example:

  • int sum = 0;    
  • float balance = 3000.0;           
  • String name = “Amar”;

Data types classified into Primitive and Non-Primitive types.

Data TypesMemory SizeRange
char1 byte-128 to 127
short2 byte-32,768 to 32,767
int4 byte-2,147,483,648 to -2,147,483,647
long8 byte?9,223,372,036,854,775,808 to 9,223,372,036,854,775,807
float4 byte1.5 * 10-45 – 3.4 * 1038, 7-digit precision
double8 byte5.0 * 10-324 – 1.7 * 10308, 15-digit precision

Character data type: Character type variable is used to store alphabets, digits and symbols.

using System;				
public class Program
{
	public static void Main()
	{
		char x = 'A';
		char y = '5';
		char z = '$';
		Console.WriteLine("x val : " + x + "\ny val : " + y + "\nz val : " + z);
	}
}

ASCII : Representation of each character of language using constant integer value.

A-65
B-66



Z-90
a-97
b-98
….
….
….
z-122
0-48
1-49
..
..
..
9-57
*-34
#-35
$-36


Scroll to Top