Sunil
Sunil

Reputation: 21416

Pass either List<string> or string[ ] array to a C# method

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;
}

Upvotes: 0

Views: 1702

Answers (1)

Tim Schmelter
Tim Schmelter

Reputation: 460340

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?

Upvotes: 7

Related Questions