Befor learning any programming language, it is verymuch important to know what are all the datatypes available and how efficiently we can use the same. Proper use of the datatypes will certainly improve the performance of the appliacation as well.
C# Data Types:
| FCL Name |
Data Type |
Bytes |
Range |
Purpose |
| SByte |
sbyte |
1 |
-128 to 127 |
|
| Byte |
byte |
1 |
0 to 255 |
|
| Int16 |
short |
2 |
-32768 to 32767 |
|
| Int32 |
int |
4 |
|
|
| UInt32 |
uint |
4 |
|
|
| Int64 |
long |
8 |
|
|
| UInt64 |
ulong |
8 |
|
|
| Single |
float |
4 |
|
Floating point numbers |
| Double |
double |
8 |
|
Large Floating point numbers |
| Decimal |
decimal |
16 |
|
Numbers which need highest precision. |
C# Console application code to check the same:
using System;
namespace LearnDataTypes
{
///
/// Program to print the size and Range of all C# Datatypes.
/// Author : Meganadha Reddy K., Date: 11-October-2010
///
class Program
{
static void Main(string[] args)
{
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}","sbyte",sizeof(sbyte),sbyte.MaxValue,sbyte.MinValue);
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}", "byte", sizeof(byte), byte.MaxValue, byte.MinValue);
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}", "short", sizeof(short), short.MaxValue, short.MinValue);
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}", "int", sizeof(int), int.MaxValue, int.MinValue);
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}", "uint", sizeof(uint), uint.MaxValue, uint.MinValue);
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}", "long", sizeof(long), long.MaxValue, long.MinValue);
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}", "ulong", sizeof(ulong), ulong.MaxValue, ulong.MinValue);
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}", "float", sizeof(float), float.MaxValue, float.MinValue);
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}", "double", sizeof(double), double.MaxValue, double.MinValue);
Console.WriteLine("sizeof({0}):{1} Bytes,\t MaxValue: {2}\tMinValue: {3}", "decimal", sizeof(decimal), decimal.MaxValue, decimal.MinValue);
Console.ReadLine();
}
}
}
Output:

C# DataTypes : Program Output
Other available datatypes will be available in next post.
Hope this will be useful to someone.
Happy coding.
Cheers,
Meganadha Reddy K.