Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert ICollection<T> to List<T>

Tags:

I am trying to convert ICollection to List using below code-

ICollection<DataStructure> list_Stuctures = dataConnectorService.ListStructures(dataConnector, SupportedDataStructures.All);  List<DataStructure> lst_DataStructure = new List<DataStructure>();  list_Stuctures.CopyTo(lst_DataStructure); 

On last line, I get below exception-

Exception = TargetParameterCountException

Message = Parameter count mismatch.

How to convert ICollection to List?

like image 818
Sagar Avatar asked Jul 04 '16 17:07

Sagar


People also ask

What is the difference between ICollection and list?

Solution 2. ICollection<T> is an interface, List<T> is a class.


1 Answers

The easiest way to convert a ICollection to a List is the usage of LINQ like (MSDN)

List<T> L = C.ToList(); 

Dont't forget to add

using System.Linq; 

otherwise ToList() is not available.

like image 60
Fruchtzwerg Avatar answered Oct 20 '22 10:10

Fruchtzwerg