如何让 params
的参数至少有一个值?
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) { }
关于C# 参数至少有一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10445743/