문제

An example of a method that uses the params keyword is String.Format("", foo, bar, baz)

But how would I make a method that accepts an array of enums like so:

class MyClass
{
    public enum Foo { Bar, Baz }

    public static void MyMethod(params enum[] Foo) {}

    public static void TestMethod()
    {
        MyMethod();
        MyMethod(Foo.Bar);
        MyMethod(Foo.Baz);
        MyMethod(Foo.Bar, Foo.Baz);
    }
}
도움이 되었습니까?

해결책

public static void MyMethod(params Foo[] values) { }

다른 팁

Try this instead

class MyClass
{
public enum Foo { Bar, Baz }

public static void MyMethod(params Foo[] foos) {}

public static void TestMethod()
{
    MyMethod();
    MyMethod(Foo.Bar);
    MyMethod(Foo.Baz);
    MyMethod(Foo.Bar, Foo.Baz);
}

}

Err..try:

public static void MyMethod(params Foo[] foo) { }
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top