Extension Method ConvertAll

c#, extension-methods

Solution

`ConvertAll` isn't an extension method, it's a real method on `List<T>` itself.

It returns a new list containing the converted elements. So in your example, the `query` variable isn't actually a query, it's a `List<double>`.

`Cast` and `OfType` are extension methods that operate on `IEnumerable` and return an `IEnumerable<T>`. However they're not suitable for your stated purpose: `Cast` can convert reference types but cannot convert value types, only unbox them. `OfType` doesn't perform any conversion, it just returns any elements that are already of the specified type.

Problem

What is the proper use of ConverAll ? Will it convert one type to another type? like ``` List<int> intList = new List<int>(); intList.Add(10); intList.Add(20); intList.Add(30); intList.Add(33); var query= intList.ConvertAll(x=>(double)x); ``` for this i can use cast or OfType<>.

Original source