Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting IList<string> to List<string>() [duplicate]

Tags:

c#

list

ilist

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?

like image 957
hoakey Avatar asked Nov 28 '22 17:11

hoakey


2 Answers

you can just do

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

or

var list = myIList as List<string>;
if (list != null) list.Sort; // ...
like image 120
Random Dev Avatar answered Dec 01 '22 06:12

Random Dev


IList<string> someVariable = GetIList();
List<string> list = someVariable.OrderBy(x => x).ToList();
like image 44
Bala R Avatar answered Dec 01 '22 08:12

Bala R