Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
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