I'm trying to access my class's private enum. But I don't understand the difference needed to get it working compared to other members;
If this works:
private double dblDbl = 2; //misc code public double getDblDbl{ get{ return dblDbl; } }
Why can I not do it with enum?
private enum myEnum{ Alpha, Beta}; //misc code public Enum getMyEnum{ get{ return myEnum; } } //throws "Window1.myEnum" is a "type" but is used like a variable
You have 2 very different things going on here.
In the first example you are defining a private field of a public type. You are then returning an instance of that already public type through a public method. This works because the type itself is already public.
In the second example you are defining a private type and then returning an instance through a public property. The type itself is private and hence can't be exposed publically.
A more equivalent example for the second case would be the following
public enum MyEnum { Alpha, Beta }
// ...
private MyEnum _value;
public MyEnum GetMyEnum { get { return _value; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With