#187 – Everything Is an Object

In C#, every data item is an object, created on the stack or the heap.  Even built-in data types, like double or int represent classes (System.Double and System.Int32) and declaring an object to be of one of these types is equivalent to instantiating an object of the appropriate type.

            // Declare and instantiate an int
            int i = 12;

            // Equivalent to
            System.Int32 i2 = new System.Int32();
            i2 = 12;

Similarly, every function call involves calling a method declared in some type–either a static or an instance method.

Even constants represent instances of some object.


About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

2 Responses to #187 – Everything Is an Object

  1. Pingback: #921 – Objects Are Explicitly Created but Automatically Destroyed | 2,000 Things You Should Know About C#

  2. Pingback: #923 – An Object Isn’t Necessarily Deleted as Soon as Its Dereferenced | 2,000 Things You Should Know About C#

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 )

Connecting to %s

%d bloggers like this: