Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I implement this public accesible enum

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
like image 803
Psytronic Avatar asked Feb 27 '23 08:02

Psytronic


1 Answers

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; } }
like image 186
JaredPar Avatar answered Mar 07 '23 17:03

JaredPar