Sun*_*nil 0 c# collections parameter-passing
我的C#类中有以下方法.
对于名为'collections'的参数,我希望能够灵活地传递List或string []数组.我知道我可以简单地将参数类型设置为对象类型,但是还有其他更高效的类型可以用来做这个吗?
public string ProcessDoc(List<string> collections, string userName)
{
//code goes here
string result = null;
...
...
return result;
}
Run Code Online (Sandbox Code Playgroud)
你可以使用IList<string>:
public string ProcessDoc(IList<string> collections, string userName)
{
//code goes here
string result = null;
...
...
return result;
}
Run Code Online (Sandbox Code Playgroud)