Why do we need struct? (C#)

后端 未结 9 1894
盖世英雄少女心
盖世英雄少女心 2021-02-05 21:18

To use a struct, we need to instantiate the struct and use it just like a class. Then why don\'t we just create a class in the first place?

9条回答
  •  隐瞒了意图╮
    2021-02-05 21:33

    In C#, a struct is a value type, unlike classes which are reference types. This leads to a huge difference in how they are handled, or how they are expected to be used.

    You should probably read up on structs from a book. Structs in C# aren't close cousins of class like in C++ or Java.

提交回复
热议问题