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.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA