Javatpoint Logo
Javatpoint Logo

LINQ Cast() Method

In LINQ, Cast operator is used to cast/convert all the elements present in a collection into a specified data type of new collection. In case if we try to cast/convert different types of elements (string/integer) in the collection, then the conversion will fail, and it will throw an exception.

Syntax of LINQ Cast () conversion operator

C# Code

Example of LINQ Cast Conversion Operator

Output:

LINQ Cast() Method

In the above example, we have an Arraylist where we added a few countries. These countries are a type of Object, and by using Cast operator, we are converting the ArrayList Object to String type object.






Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA