What's the difference between struct and class in .NET?

前端 未结 19 1601
一向
一向 2020-11-22 01:51

What\'s the difference between struct and class in .NET?

19条回答
  •  醉梦人生
    2020-11-22 02:09

    Structure vs Class

    A structure is a value type so it is stored on the stack, but a class is a reference type and is stored on the heap.

    A structure doesn't support inheritance, and polymorphism, but a class supports both.

    By default, all the struct members are public but class members are by default private in nature.

    As a structure is a value type, we can't assign null to a struct object, but it is not the case for a class.

提交回复
热议问题