Tuesday, May 13, 2008

Briefly describe how a class is similar to a structure. How are they different?

Both classes and structures can have members such as methods, properties, and fields, both use a constructor for initialization, and both inherit from System.Object. Both classes and structures can be used to model realworld objects.

Classes are reference types, and the memory that holds class instances is allocated on the heap. Structures are value types, and the memory that holds structure instances is allocated on the stack.

No comments: