1

As we all know that everything in C# is derived from Object class.

Then why struct is value type and class is reference type? I mean struct (type) itself has derived from Object class (class type) then how we can say that struct is not a reference type?

Arghya C
  • 9,805
  • 2
  • 47
  • 66
Manish Dubey
  • 706
  • 4
  • 17
  • There is a bunch of differences between `struct`s and `class'es. The fact they both inherit from `object` does not matter here. It's a design choice to have a common type for both ref and value types, but it also introduces some additional complexity to the language, like boxing. You should also look into `ValueType` class which is a base class for all value types in .NET. – MarcinJuraszek Sep 15 '15 at 04:53
  • 3
    IMHO this question is NOT a duplicate. As the referenced "original" question does not elaborate at all as to how it can be that deriving from a **class** Object yields a **structure**. – BitTickler Sep 15 '15 at 04:57
  • 2
    MarcinJurasek Please read the question carefully before reaching to any conclusion :) – Manish Dubey Sep 15 '15 at 05:01
  • While I agree that it is ***close***, I don't think that this is actually a duplicate. That said, it may also not be a good fit for SO since the answer may be too broad or too opinionated, unless one of language designers/developers can chime in, since only they can say WHY the decision was made. – David L Sep 15 '15 at 05:03
  • 1
    It's NOT a duplicate of the marked question, and is a pretty fair question IMHO. – Arghya C Sep 15 '15 at 05:15
  • 2
    @MarcinJuraszek this http://stackoverflow.com/questions/1682231/how-do-valuetypes-derive-from-object-referencetype-and-still-be-valuetypes is closer to what one would call as duplicate. Hope now OP gets the answer he's looking for. – Nikhil Vartak Sep 15 '15 at 05:45

0 Answers0