C# fundamental sort of information types: Here, we will find out about the necessary kinds of information types in C# with their framework types, involved size, esteem range and worth sorts.
Here is the rundown of the inherent basic sorts of information types in C#, sbyte, byte, scorch, short, ushort, int, uint, long and ulong
Type | System type | Size (in bits) | Value Range | Value type |
sbyte | System.SByte | 8-bits | -128 to 127 | Signed integer |
byte | System.Byte | 8-bits | 0 to 255 | Unsigned integer |
char | System.Char | 16-bits | U+0000 to U+ffff | Unicode character |
short | System.Int16 | 16-bits | -32,768 to 32,767 | Signed integer |
unshort | System.Int16 | 16-bits | 0 to 65,535 | Unsigned integer |
int | System.Int32 | 32-bits | -2,147,483,648 to 2,147,483,647 | Signed integer |
unint | System.Int32 | 32-bits | 0 to 4,294,967,295 | Unsigned integer |
long | System.Int64 | 64-bits | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | Signed integer |
ulong | System.Int64 | 64-bits | 0 to 18,446,744,073,709,551,615 | Unsigned integer |
Example:
In this example, we are proclaiming factors of various necessary kinds of information types, introducing with the distinctive worth, printing the framework sorts of the factors, size of the sorts and min, max estimations of the sorts.
using System;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
//sbyte
sbyte a = -10;
Console.WriteLine("sbyte...");
Console.WriteLine("a = " + a);
Console.WriteLine("type of variable = " + a.GetType());
Console.WriteLine("size of sbyte = " + sizeof(sbyte));
Console.WriteLine("Min value of sbyte = " + sbyte.MinValue);
Console.WriteLine("Max value of sbyte = " + sbyte.MaxValue);
Console.WriteLine();
//byte
byte b = 10;
Console.WriteLine("byte...");
Console.WriteLine("b = " + b);
Console.WriteLine("type of variable = " + b.GetType());
Console.WriteLine("size of byte = " + sizeof(byte));
Console.WriteLine("Min value of byte = " + byte.MinValue);
Console.WriteLine("Max value of byte = " + byte.MaxValue);
Console.WriteLine();
//char
char c = 'P';
Console.WriteLine("char...");
Console.WriteLine("c = " + c);
Console.WriteLine("type of variable = " + c.GetType());
Console.WriteLine("size of char = " + sizeof(char));
Console.WriteLine("Min value of char = " + (int)(char.MinValue));
Console.WriteLine("Max value of char = " + (int)(char.MaxValue));
Console.WriteLine();
//short
short d = -18910;
Console.WriteLine("short...");
Console.WriteLine("d = " + d);
Console.WriteLine("type of variable = " + d.GetType());
Console.WriteLine("size of short = " + sizeof(short));
Console.WriteLine("Min value of short = " + short.MinValue);
Console.WriteLine("Max value of short = " + short.MaxValue);
Console.WriteLine();
//ushort
ushort e = 18910;
Console.WriteLine("ushort...");
Console.WriteLine("e = " + e);
Console.WriteLine("type of variable = " + e.GetType());
Console.WriteLine("size of ushort = " + sizeof(short));
Console.WriteLine("Min value of ushort = " + ushort.MinValue);
Console.WriteLine("Max value of ushort = " + ushort.MaxValue);
Console.WriteLine();
//int
int f = -893818910;
Console.WriteLine("int...");
Console.WriteLine("f = " + f);
Console.WriteLine("type of variable = " + f.GetType());
Console.WriteLine("size of int = " + sizeof(int));
Console.WriteLine("Min value of int = " + int.MinValue);
Console.WriteLine("Max value of int = " + int.MaxValue);
Console.WriteLine();
//uint
int g = 893818910;
Console.WriteLine("uint...");
Console.WriteLine("g = " + g);
Console.WriteLine("type of variable = " + g.GetType());
Console.WriteLine("size of uint = " + sizeof(uint));
Console.WriteLine("Min value of uint = " + uint.MinValue);
Console.WriteLine("Max value of uint = " + uint.MaxValue);
Console.WriteLine();
//long
long h = -90909893818910;
Console.WriteLine("long...");
Console.WriteLine("h = " + h);
Console.WriteLine("type of variable = " + h.GetType());
Console.WriteLine("size of long = " + sizeof(long));
Console.WriteLine("Min value of long = " + long.MinValue);
Console.WriteLine("Max value of long = " + long.MaxValue);
Console.WriteLine();
//ulong
ulong i = 90909893818910;
Console.WriteLine("ulong...");
Console.WriteLine("i = " + i);
Console.WriteLine("type of variable = " + i.GetType());
Console.WriteLine("size of ulong = " + sizeof(ulong));
Console.WriteLine("Min value of ulong = " + ulong.MinValue);
Console.WriteLine("Max value of ulong = " + ulong.MaxValue);
Console.WriteLine();
//hit ENTER to exit
Console.ReadLine();
}
}
}
Output:
sbyte...
a = -10
type of variable = System.SByte
size of sbyte = 1
Min value of sbyte = -128
Max value of sbyte = 127
byte...
b = 10
type of variable = System.Byte
size of byte = 1
Min value of byte = 0
Max value of byte = 255
char...
c = P
type of variable = System.Char
size of char = 2
Min value of char = 0
Max value of char = 65535
short...
d = -18910
type of variable = System.Int16
size of short = 2
Min value of short = -32768
Max value of short = 32767
ushort...
e = 18910
type of variable = System.UInt16
size of ushort = 2
Min value of ushort = 0
Max value of ushort = 65535
int...
f = -893818910
type of variable = System.Int32
size of int = 4
Min value of int = -2147483648
Max value of int = 2147483647
uint...
g = 893818910
type of variable = System.Int32
size of uint = 4
Min value of uint = 0
Max value of uint = 4294967295
long...
h = -90909893818910
type of variable = System.Int64
size of long = 8
Min value of long = -9223372036854775808
Max value of long = 9223372036854775807
ulong...
i = 90909893818910
type of variable = System.UInt64
size of ulong = 8
Min value of ulong = 0
Max value of ulong = 18446744073709551615