C#datatypes
C#datatypes
=================
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
Character Types
================
Char System.Char 2-bytes
String System.String it is depends on the
value assigned to it
value types:
==========
all the fixed length data types comes under the categories of value types
ex:
int ,float,char,bool etc
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
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;
}
}
}
/*
* 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
*/