1.

Structs Are Largely Redundant In C++. Why Does C# Have Them?

Answer»

In C++, a struct and a CLASS are pretty much the same thing. The only difference is the default visibility level (PUBLIC for structs, private for CLASSES). However, in C# structs and classes are very DIFFERENT. In C#, structs are value types (INSTANCES stored directly on the stack, or inline within heap-based objects), whereas classes are reference types (instances stored on the heap, accessed indirectly via a reference). Also structs cannot inherit from structs or classes, though they can implement interfaces. Structs cannot have destructors. A C# struct is much more like a C struct than a C++ struct.

In C++, a struct and a class are pretty much the same thing. The only difference is the default visibility level (public for structs, private for classes). However, in C# structs and classes are very different. In C#, structs are value types (instances stored directly on the stack, or inline within heap-based objects), whereas classes are reference types (instances stored on the heap, accessed indirectly via a reference). Also structs cannot inherit from structs or classes, though they can implement interfaces. Structs cannot have destructors. A C# struct is much more like a C struct than a C++ struct.



Discussion

No Comment Found