如何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
}
Run Code Online (Sandbox Code Playgroud)
Nic*_*ick 31
做就是了:
public void Foo(string first, params string[] s) { }
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3242 次 |
| 最近记录: |