In LINQ, conversion operators are useful to convert the type of elements in the list/collection. In LINQ, we have different types of conversion operators available those are
Using these conversion operators, we can convert the type of elements in the list.
The following table shows more detailed information related to conversion operators.
Operator | Description |
---|---|
ToList | It converts a collection to List |
ToArray | It converts a collection to an array |
ToLookUp | It converts a group of elements into Lookup<tkey, telement> |
Cast | It converts non-generic list to generic list (IEnumerable to IEnumerable) |
OfType | It is useful to filter collection based on a specified type |
AsEnumerable | It is useful to convert input elements as IEnumerable |
AsQueryable | It converts IEnumerable to IQueryable |
ToDictionary | It converts input elements into a dictionary based on the key selector function. |
In the coming chapters, we will learn each conversion operator with examples.