Click here to Skip to main content
15,902,939 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Ienumerable<string> t;
Public List<string> folder=new List<string>();

Folder=t;

Send.FSend(path,t,”error”); // t is error and cannot implicity error.

How to solve this problem.

What I have tried:

Ienumerable<string> t;
Public List<string> folder=new List<string>();

Folder=t;

Send.FSend(path,t,"error"); // t is error and cannot implicity error
Posted
Updated 20-Feb-19 22:28pm

1 solution

t is an IEnumerable<T>, not a List<T>
And folder can only contain Lists which are a "superset" of IEnumerable.

You can do it the other way around:
C#
IEnumerable<string> t;
List<string> folder = new List<string>();
t = folder;
Because every List is IEnumerable - but you can't do it the other way.

Think about it: what would happen if you could? When you tried to use the List, the List specific features (indexing, adding and removing items, etc.) would not be there, so teh code would fail.

You can do it by using a Linq method to convert the IEnumerable to a List:
C#
IEnumerable<string> t = ...;
List<string> folder = t.ToList();
But that creates a new object (a List) which contains the same items as the original IEnumerable, but which is not "attached" to it, so changes to one will not affect the other.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900