Javatpoint Logo
Javatpoint Logo

LINQ ToDictionary() Method

In LINQ, ToDictionary() Method is used to convert the items of list/collection(IEnumerable<T>) to new dictionary object (Dictionary<TKey,TValue>) and it will optimize the list/collection items by required values only.

Syntax of LINQ ToDictionary Method

Here is the syntax of using the LINQ ToDictionary() operator.

C# Code

In the above syntax, we are converting the collection of "objStudent" to dictionary object and getting the only required filled value (ID and Name).

Example of ToDictionary method

Here is the example of using the LINQ ToDictionary operator to convert the collection to the new dictionary object.

In the above example, we are converting the collection of "objStudent" to dictionary objects and getting the values from the two values (ID and Name).

OUTPUT:

LINQ ToDictionary() Method




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA