Javatpoint Logo
Javatpoint Logo

LINQ ToArray() Method

ToArray() operator in LINQ is used to convert the input elements in the collection to an Array.

Syntax of LINQ ToArray() operator

The syntax of using the LINQ ToArray() operator to convert the collection to an array.

C# Code

In the above syntax, we are converting the collection of "countries" to an Array.

Example of LINQ ToArray() operator in method syntax

In this example, we are using LINQ ToArray() operator in method syntax to convert the input collection items to new array.

In the above example, we have a List of type string "countries." By using the ToArray() method, we converted the list of "countries" List to an Array. To access these elements, we have iterated the array in a foreach loop and displayed it on the screen.

OUTPUT:

LINQ ToArray() Method

LINQ ToArray() operator in Query Syntax

The example of using LINQ ToArray() operator in Query Syntax is:

OUTPUT:

LINQ ToArray() Method





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