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) { }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.