C# enums as function parameters?

后端 未结 7 1381
广开言路
广开言路 2021-01-04 00:10

Can you pass a standard c# enum as a parameter?

For example:

enum e1
{
    //...
}

enum e2
{
    //...
}

public void test()
{
    myFunc( e1 );
           


        
7条回答
  •  鱼传尺愫
    2021-01-04 00:12

    correct is:

    public void myFunc(Enum e)
    {
        foreach (var name in Enum.GetNames(e.GetTye()))
        {
            Console.WriteLine(name);
        }
    }
    

提交回复
热议问题