Как привести List
к List
?
(где SomethingElse
, как известно, происходит от object
)
Бонусная болтовня
Приведение списка:
List<Object> first = ...;
List<SomethingElse> second = (List<SomethingElse>)first;
не работает:
Не удается преобразовать тип 'System.Collections.Generic.List' в 'System. Collections.Generic.List'
Casting the list:
List<SomethingElse> second = first.Cast<SomethingElse>();
не работает:
Cannot implicitely convert type 'System.Collections.Generic.List' to 'System.Collections.Generic.List'
на самом деле мне не нужен полный объект List
, достаточно ICollection
:
ICollection<SomethingElse> second = first;
ICollection<SomethingElse> second = (ICollection<SomethingElse>)first;
ICollection<SomethingElse> second = first.Cast<SomethingElse>();
не работает.