user34537
user34537

Reputation:

Are classes boxed? .NET

I was wondering, does a class get boxed? I always assumed every class had a virtual table which can be used to identify the class, so does it need to be boxed?

Upvotes: 2

Views: 170

Answers (3)

Brian Rasmussen
Brian Rasmussen

Reputation: 116401

No. Classes are reference types so no need for boxing. Boxing is used to represent values as objects (in order to provide .NET's unified type system). As instances of classes are already objects they never need to be boxed.

Upvotes: 3

Oded
Oded

Reputation: 499002

No they are not.

Boxing referes to a primite type (int, char, long etc...) being wrapped into a class (i.e. boxed).

Upvotes: 1

itowlson
itowlson

Reputation: 74802

Only value types (structs) get boxed. Class instances do not get boxed.

Upvotes: 3

Related Questions