Search code examples
c#listilist

Converting IList<string> to List<string>()


I have a function that takes IList<string> someVariable as a parameter. I want to convert this to a list so I can sort the values alphabetically.

How do I achieve this?


Solution

  • you can just do

    var list = new List<string>(myIList);
    list.Sort();
    

    or

    var list = myIList as List<string>;
    if (list != null) list.Sort; // ...