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?
Solution 2. ICollection<T> is an interface, List<T> is a class.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With