Saturday, December 5, 2009

Data Type in C#.net















Data TypeDescription Example
object The base type of all typesobject obj = null;
stringString type - sequence of Unicode charactersstring str = "Harsha";
sbyte8-bit signed integral typesbyte val = 15;
short16-bit signed integral typeshort val = 15;
int 32-bit signed integral typeint val = 15;
long 64-bit signed integral type long val1 = 15;
long val2 = 34L;
boolBoolean type; a bool value is either true or falsebool val1 = true;bool val2 = false;
charCharacter type; a char value is a Unicode character char val = 'h';
byte 8-bit unsigned integral typebyte val1 = 15;
byte val2 = 34U;
ushort 16-bit unsigned integral type ushort val1 = 15;
ushort val2 = 34U;
uint32-bit unsigned integral typeuint val1 = 15;
uint val2 = 34U;
ulong 64-bit unsigned integral typeulong val1 = 15;
ulong val2 = 34U;
ulong val3 = 56L;
ulong val4 =78UL;
float Single-precision floating point type float val = 1.23F;
double Double-precision floating point typedouble val1 = 1.23;
double val2 = 4.56D;
decimal
Precise decimal type with 28 significant digitsdecimal val= 1.23M;




Types in C#

C# supports two kinds of types: value types and reference types.





TypeDescription
Value Types Includes simple data types such as int, char, bool, enums
Reference Types Includes object, class, interface, delegate, and array types

Value Types- Value type objects direct contain the actual data in a variables. With value types, the variables each have their own copy of the data, and it is not possible for operations on one to affect the other.

int i = 10;

Reference Types- Reference type variables stores the reference of the actual data. With reference types, it is possible for two variables to reference the same object, and thus possible for operations on one variable to affect the object referenced by the other variable.

MyClass cls1 = new MyClass();

Data Type Conversions

C# supports two types of conversions. Implicit conversions and explicit conversions.

Implicit conversions are direct conversion. For example:

int iVal = 34;
long lVal = intValue;

Explicit conversions includes type casting. conversion. For example:

long lVal = 123456;
int iVal = (int) lVal;

1 comment:

  1. Good Yar ,Thank u for giving the solution for publish uor site in our workgroup .
    Its working .Cary on Cary On ...............

    ReplyDelete