inforakesha

A fine WordPress.com site

Checked code , typeof, sizeof

Leave a comment

OverFlow
Overflow is not checked by default
int x=1000000;
x=x*X//-727379968 no error

x=checked(x*x);// System.OverflowException
checked{
………
x=x*x; //System.OverflowException
}

Overflow check can be turned on with a compiler switch
csc/checked Test.cs

typeof and sizeof
typeof:-
-Returns the type descriptior of given type.
The type decriptor of an object typr can be retrived with o.GetType().

sizeof:-
-Returns the size of a type in bytes.
-can only be applied to the valu type.
-Can only be used in unsafe block.

unsafe{

Console.WriteLine(sizeof(int));
Console.WriteLine(sizeof((MyEnumType));
}

Visibility Modifier
public:- Visible where the declaring the namesapce is known.
-Member of inteface and enumeration are public by default.
-Types in a namesapce (classes, structs, interfaces, enums, delegates)
have default visibility intenal.
private:- only visible in decalring class or struct.
-private is also default modifier (field, method , properties) in a class.

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s