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<>.
ConvertAllisn’t an extension method, it’s a real method onList<T>itself.It returns a new list containing the converted elements. So in your example, the
queryvariable isn’t actually a query, it’s aList<double>.CastandOfTypeare extension methods that operate onIEnumerableand return anIEnumerable<T>. However they’re not suitable for your stated purpose:Castcan convert reference types but cannot convert value types, only unbox them.OfTypedoesn’t perform any conversion, it just returns any elements that are already of the specified type.