How to convert a general list to a list?
I use ListCollectionView, and I need to provide it IListnot a IList<T>.
ListCollectionView
IList
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>)?
new List().AddRange(IList<T>
As List<T>the interface implements IList, you can simply provide List<T>. If necessary, just enter it:
List<T>
List<int> list = new List<int>(); IList ilist = (IList)list;
To clarify other answers:
IList<T> , IList. IEnumerable<T> IEnumerable. IEnumerable<T>, T . ; .
IEnumerable<T>
IEnumerable
, List<T> IList. List<Giraffe>, IList, .
List<Giraffe>
, : , , - IList<T>, IList "as", , ArrayList List<object> . List<T>, -, IList .
ArrayList
List<object>
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.
(IList)theList