Thursday, October 7, 2010
What is Value type and Reference type ? Whats the difference between Struct and class ?
A struct is a value type. To help understand the struct, it's helpful to make a comparison with classes.While a struct is a value type, a class is a reference type. Value types hold their value in memory where they are declared, but reference types hold a reference to an object in memory. If you copy a struct, C# creates a new copy of the object and assigns the copy of the object to a separate struct instance. However, if you copy a class, C# creates a new copy of the reference to the object and assigns the copy of the reference to the separate class instance. Structs can't have destructors, but classes can have destructors. Another difference between a struct and class is that a struct can't have implementation inheritance, but a class can. Although a struct can't have implementation inheritance, it can have interface inheritance.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment