I have an object which can be of any collection type like IEnumerable or IQueryable or List.
Now i want this object to be converted into type List.
Can anyone tell me how can i achieve this??
Thanks
I have an object which can be of any collection type like IEnumerable or IQueryable or List.
Now i want this object to be converted into type List.
Can anyone tell me how can i achieve this??
Thanks
If you have .net 3.5 and System.Linq:
List<NewType> converted =
myUnknownEnumeration.OfType<NewType>().ToList();
You need OfType to do the conversion (you can use Cast<>()
instead if you want to throw an exception for any of the the wrong type) and ToList converts anything enumerable into a list.
You could cast your object to IEnumerable(T), then call ToList on it (.NET 3.5 required).
public List getdata() { ProductsDataContext obj = new ProductsDataContext(); List objlist = (from p in obj.nik_Products2s select new { p.Id, p.Price, p.ProdDesc, p.ProductName }).OfType().ToList(); return objlist; }
I have code like below
public List getdata() { ProductsDataContext obj = new ProductsDataContext(); List objlist = (from p in obj.nik_Products2s select new { p.Id, p.Price, p.ProdDesc, p.ProductName }).OfType().ToList(); return objlist; }
here nik_products2 table's data is fatched and converted into generic list.
its fine and solve the error of converting ienumerable to list,
But still its not getting data.
means no data was found when you used oftype<>().