Saturday, June 5, 2010

C#

C# doesn't support multiple inheritance. It doesn't have pointers. Class objects can be referred only through references. Unlike C++, there is no concept of structure. Properties are supported, which are like class fields with a getter and/or setter function.

Data types

C# has 15 value types.

Following are the integer value types used to store whole numbers:
long : 64 bits
int : 32 bits
short : 16 bits
byte : 8 bits

Numbers having decimal places can use the following:

float : 32 bits :single precision
double : 64 bits : double precision
decimal : 128 bits : most accurate

Following are the non-numeric data types:

bool : 8 bits
string : depends on size of string
char : 16 bits

Other data types include :

Arrays : In C# array is an object. They are declared as follows
int [] var[10];
And initialized as follows
var = new int[10];

Reference In C# references are labels for objects. For a class Box, an object reference is declared like this
Box box;
At this point box is set to null. The following statement makes box refer an instance of Box type.
box = new Box();
If no reference exits to an object, it is garbage collected by the CLR.

Properties : Properties in C# can be declared like this
public int numberofBox
{
get
{ ... }
set
{ ... }
}
Through properties calculation associated with backing fields can be performed by using get / set functions.

Interfaces : Different types of objects can support a common functionality by implementing an interface. A class implements an interface by declaring like this:

class Box : IBox
{
...
}

It's possible to create references using IBox interface:
IBox ibox = new Box();

This "is" keyword can determine whether an object supports a type (class or interface)

if( ibox is IBox)

No comments:

Post a Comment