Overriding the Defaults in a struct (c#)

前端 未结 12 999
感情败类
感情败类 2021-01-04 00:47

Is it possible to set or override the default state for a structure?

As an example I have an

enum something{a,b,c,d,e};

and a struc

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-04 01:33

    You can't. Structs always have a default constructor that sets every member to its default value (null for reference types, 0 for numeric types, false for bools, etc.) This behavior cannot be changed.

提交回复
热议问题