Overriding the Defaults in a struct (c#)

前端 未结 12 1015
感情败类
感情败类 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:15

    Struct constructors are similar to class constructors, except for the following differences:

    Structs cannot contain explicit parameterless constructors. Struct members are automatically initialized to their default values. A struct cannot have an initializer in the form: base (argument-list).

    http://msdn.microsoft.com/en-us/library/aa288208(v=vs.71).aspx

    So, short answer, no you can't override the default constructor (every struct has a parameterless constructor and you can't hide it or override it)...

提交回复
热议问题