Objects in C#

(Almost) Everything is an object is .net and C#. We all know that int, char, string, date, double etc are the primitive data types. But all these data types are derived from system.object.

To understand this lets take an example of int data type. We all know that int is derived from System.Int32; but we can declare the variable of int type using below mentioned two ways

int i = new int();
int j = 0;

where first option is like abject instance creation. When we use the . (dot) operator on i then it will give us different methods like .ToString(), .Equals() for object equality, .GetType() to get type. Hence this proves that all these primitives data types also derived from object (system.object) base class.

datatype

 

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s