Javatpoint Logo
Javatpoint Logo

LINQ OfType() Method

OfType() operator is used to return the element of the specific type, and another element will be ignored from the list/collection.

Syntax of LINQ OfType() Operator

The syntax of using the OfType () LINQ Operator is to get the specified type of elements from the list/collection is:

C# Code

In the above syntax, we are trying to get only the string elements from the collection of "obj" by using the OfType operator.

Example of LINQ OfType () operator

Here is the example of the LINQ OfType() operator to get the only specified type of elements from the list/collection.

In the above example, from "result" list, we are trying to get only those elements, which are the type of string. The last element is ignored because it is an integer.


LINQ OfType() Method

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA