How to convert a general list <T> to a list?

How to convert a general list to a list?

I use ListCollectionView, and I need to provide it IListnot a IList<T>.

I see many examples for converting IListto IList<T>, but not the other way around.

Am I just converting it manually ( new List().AddRange(IList<T>)?

+5
source share
3 answers

As List<T>the interface implements IList, you can simply provide List<T>. If necessary, just enter it:

List<int> list = new List<int>();
IList ilist = (IList)list;
+9
source

To clarify other answers:

IList<T> , IList. IEnumerable<T> IEnumerable. IEnumerable<T>, T . ; .

, List<T> IList. List<Giraffe>, IList, .

, : , , - IList<T>, IList "as", , ArrayList List<object> . List<T>, -, IList .

+10

You do not need to convert at all. A List<T>implements an interface IList.

If you need a type IList, for example, to use a specific overload, just use the cast syntax (IList)theList.

+2
source

All Articles