Overriding the Defaults in a struct (c#)

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

    Kinda dumb, but works

    public readonly static float default_value = 1;
    public struct YourStruct{
    
        public float yourValue{
            get {
                return _yourValue + default_value;
            }
            set {
                _yourValue= value - default_value;
            }
        }
        public float _yourValue;
    }
    

提交回复
热议问题