1
Reply

Structs are largely redundant in C++.Why does C# have them?

Samir Bhogayta

Samir Bhogayta

Jun 25, 2016
474
0

    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.

    Samir Bhogayta
    June 25, 2016
    0