Built in Types in C#

Built in Types

In the previous tutorial of our C# learning series, We have learnt how to Read and write data to Console and the ways of writing data to console i.e. by using Place holder syntax and concatenation syntax.

In this tutorial, We are going to learn the built in types in C# like byte,int,float etc. These are used extensively from writing a simple program to a complex program.

Buit in Types in C#

Type Represents Range Default Value
bool Boolean value True or False False
byte 8-bit 0 to 255 0
char 16-bit U +0000 to U +ffff ‘\0’
decimal 128-bit (-7.9 x 1028 to 7.9 x 1028)
/ 100 to 28
double 64-bit (+/-)5.0 x 10-324 to (+/-)1.7 x 10308 0.0D
float 32-bit -3.4 x 1038 to + 3.4 x 1038 0.0F
int 32-bit -2,147,483,648 to 2,147,483,647 0
long 64-bit -9,223,372,036,854,775,808 to
sbyte 8-bit -128 to 127 0
short 16-bit -32,768 to 32,767 0
uint 32-bit 0 to 4,294,967,295 0
ulong 64-bit 0 to 18,446,744,073,709,551,615 0
ushort 16-bit 0 to 65,535 0

There is another way to find the minimum value and maximum value directly from your IDE. All you have to do is to write one line of code in your visual studio

Console.WriteLine(“min value of int is “+int.MinValue)
Console.WriteLine(“max value of int is {0}”,int.MaxValue)

What happens if we sote one Data type in another Data type?

In a Data type like bool(boolean), we can store only true or false. If we try to store any other value, the compiler will throw an error. Similarly, if we try to store float data type value in int , the compiler will throw an error. But, the reverse is possible. We can store int value in float data type. These are called implicit and explicit conversions.We will cover them in our later sessions.

Leave a Reply

Your email address will not be published. Required fields are marked *