I heard that nesting of enum is not possible in C#. Then how can convert the following structure to a class hierarchy or something else. So I want the class to act as an enum

I heard that nesting of enum is not possible in C#. Then how can convert the following structure to a class hierarchy or something else. So I want the class to act as an enum

nested classes and const fields
class Cat1
{
public const int Public = 1;
public class Private
{
public const int Abc = 2;
public const int Mno = 3;
public const int Pqr = 4;
}
}
int, so could get given an invalid value from somewhere else.You should rethink if you want to solve this problems via enums because the first enum category represents to me some kind of "visibility" concept while the second category is only valid of instances with visibility "public".
What about solving your issue with something like this:
public enum Visibility
{
Public,
Private
}
public abstract class VisibilityState
{
public Visibility Visibility { get; private set; }
protected VisibilityState(Visibility visibility)
{
Visibility = visibility;
}
}
public class PublicVisibilityState : VisibilityState
{
public PublicVisibilityState() : base(Visibility.Public) { }
}
public class PrivateVisibilityState : VisibilityState
{
public PrivateVisibilityState() : base(Visibility.Private) { }
public OtherEnum OtherEnumState { get; set; }
}
public enum OtherEnum
{
Abc, Mno, Pqr
}