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.
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.
LINQ ToArray() operator in Query Syntax
The example of using LINQ ToArray() operator in Query Syntax is: