You are on page 1of 4

Data types in c sharp:

=================
Interger types
**************
c# types IL Types size/capacity
======= ======= ===========
byte System.Byte 0-255
short System.Int16 -32768 -- 32767
int System.Int32 - 2^31----2^31-1
long System.Int64 -2^63---2^63-1
sbyte System.SByte -128---127
ushort System.UInt16 -0--65535
uint System.UInt32 -0-- -2^32-1
ulong System.Uint64 -0 -- -2^64-1

Decimal or float types


====================
c# type iltype size/capacity
======= ======= ============
float System.Single 4bytes
double System.Double 8bytes
decimal System.Decimal 16-bytes
Boolean types
=================
bool System.boolean true/false

Character Types
================
Char System.Char 2-bytes
String System.String it is depends on the
value assigned to it

Data types are divided into two types


====================================
1. value types
2.Reference types

value types:
==========
all the fixed length data types comes under the categories of value types
ex:
int ,float,char,bool etc

==> value types are stored in a stack memory area

Reference types
================
all variable length types comes under the category of Reference type
example:
=====
1.string
2.Object

-->in case of reference type ,values are stored on heap and their address will be
stored on stack memory

-->in C# heap is managed easily because it is controlled by garbage collector(clr)


the heap is called as managed heap

Dynamic type:
==========
introduced in c#4.0 which allows to declare variables and fields as dynaimic type.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplicationcontrolstructures
{
class Class4
{
int i = 40;//field
int j;

static void Main()


{
int y=32;
int x = 10;
Class4 c4 = new Class4();
Console.WriteLine(x);//10
Console.WriteLine(c4.i);//40
Console.WriteLine(c4.j);//0
Console.WriteLine(y);
Console.ReadLine();

}
}
}
/*
* 10
40
0
32

*/

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplicationcontrolstructures
{
class Class5
{
static void Main()
{
var i = 100;
Console.WriteLine(i.GetType());
var f = 3.14f;
Console.WriteLine(f.GetType());
Console.WriteLine(i);
Console.WriteLine(f);
var b = true;
Console.WriteLine(b.GetType());
Console.WriteLine(b);
var s = "namratha";
Console.WriteLine(s.GetType());
Console.WriteLine(s);
Console.WriteLine();
dynamic d;
d = 100;
Console.WriteLine(d);
d = 3.14f;
Console.WriteLine(d);
d = true;
Console.WriteLine(d.GetType());
d = "hello";
Console.WriteLine(d);

Console.ReadLine();
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApplicationcontrolstructures
{
class Datatypes
{
static void Main()
{
int i = 10;
Console.WriteLine(i);
Console.WriteLine(i.GetType());
float f = 3.4f;
Console.WriteLine(f);
Console.WriteLine(f.GetType());
Console.WriteLine(f.GetHashCode());
decimal de = 1234.6864m;
Console.WriteLine(de);
Console.WriteLine(de.GetType());
string s1 = "123";
Console.WriteLine(s1);
Console.WriteLine(s1.GetType());
bool b1 = true;
Console.WriteLine(b1);
Console.WriteLine(b1.GetType());
Console.ReadLine();

}
}
}
/* output:
* 10
System.Int32
3.4
System.Single
1079613850
1234.6864
System.Decimal
123
System.String
True
System.Boolean
*/

You might also like