C# enums as function parameters?

后端 未结 7 1377
广开言路
广开言路 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:39

    Like this:

        public void myFunc(Enum e)
        {
            foreach (var name in Enum.GetNames(typeof(e)))
            {
                Console.WriteLine(name);
            }
        }
    
    0 讨论(0)
提交回复
热议问题