Note that there are some explanatory texts on larger screens.

plurals
  1. POIs everything in .NET an object?
    text
    copied!<p>Please help us settle the controversy of <em>"Nearly" everything is an object</em> (<a href="https://stackoverflow.com/questions/436079/as-a-novice-is-there-anything-i-should-beware-of-before-learning-c#436092">an answer to Stack Overflow question <em>As a novice, is there anything I should beware of before learning C#?</em></a>). I thought that was the case as everything in Visual Studio at least appears as a struct. Please post a reference, so that it doesn't become "modern jackass" (<a href="http://en.wikipedia.org/wiki/This_American_Life" rel="nofollow noreferrer">This American Life</a>).</p> <p>Note that this question refers to C#, not necessarily .NET, and how it handles the data under the hood (obviously it's all 1's and 0's).</p> <p>Here are the comments to "everything is an object":</p> <ul> <li>Eh, no, it's not. – Binary Worrier</li> <li>I'd like an example... – scotty2012</li> <li>isn't everything derived from the base type Object? – rizzle</li> <li>Most things are objects... – Omar Kooheji</li> <li>Value types, ints, doubles, object references (not the objects them selves) etc aren't objects. They can be "boxed" to look like objects (e.g. i.ToString()) but really they're primitive types. Change the entry to "NEARLY everthing is an object" and I'll remove the downvote – Binary Worrier</li> <li>I appreciate the clarification. I think the lowest level that you can interact with, say an int, in C# is as a struct, which isn't an object? - <a href="http://msdn.microsoft.com/en-us/library/ms173109.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms173109.aspx</a> – rizzle</li> <li>Doesn't Int32 inherit from ValueType which inherits from Object? If so, despite the behavior, an int is an object. – Chris Farmer</li> <li>No, the boxed type for int inherits from ValueType, which inherits from Object. They're not objects in the traditional sense because a) an int isn't a reference to an int, IT IS the int. b) ints aren't garbage collected. If you declare an Int32, then that int is 4 bytes on the stack, end of story – Binary Worrier</li> </ul> <p>Definition of object: "Object" as a inheritor of class System.Object vs. "object" as an instance of a type vs. "object" as a reference type."</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload