C#参数至少有一个值

如何使用至少有一个值的参数参数?

 public void Foo(params string[] s) { } public void main() { this.Foo(); // compile error this.Foo(new string[0]); // compile error this.Foo({ }); // compile error this.Foo("foo"); // no error this.Foo("foo1", "foo2"); // no error } 

做就是了:

 public void Foo(string first, params string[] s) { } 

您无法在编译时为params指定此类条件。

但是,您可以在运行时检查此项,并在未满足指定条件时抛出exception。