Convert IEnumerable to <string> in .net 2.0
1 answer
You can pass the enumerated directly to the constructor of the new List<string> instace:
List<string> list = new List<string>(yourEnumerable); or you can use the AddRange method:
List<string> list = new List<string>(); list.AddRange(yourEnumerable); This answer assumes that you actually already have an IEnumerable<string> .
If not, the only option is a loop:
List<string> list = new List<string>(); foreach(object item in yourEnumerable) list.Add(item.ToString()); By the way: you say:
one way is to use this to add each object to the list, but this process depends on the time
You need to list the enumerated value anyway. How else do you get all the values? In the first two code examples I gave you, the listing is done inside the List<T> class, but it is still happening.
+13