I have the following method in my C# class.

For the parameter called 'collections' I would like to have the flexibility of either passing a List or string[ ] array. I know I could simply set the parameter type as object type, but is there any other more efficient type I could use to do this?

public string ProcessDoc(List<string> collections, string userName)
{
  //code goes here
   string result = null;
   ...
   ...
   return result;
}
有帮助吗?

解决方案

You could use IList<string>:

public string ProcessDoc(IList<string> collections, string userName)
{
  //code goes here
   string result = null;
   ...
   ...
   return result;
}

Why array implements IList?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top