Linq ToDictionary Extension

Linq ToDictionary Extension

Linq ToDictionary Method. Here we will find the element from dictionary collection.

  1. Linq Chapter 1 – Split string to list of strings.
  2. Linq Chapter 2 – Remove duplicates from list.
  3. Linq Chapter 3 – Linq Where Clause.
  4. Linq Chapter 4 – Linq Group by multiple clause.
  5. Linq Chapter 5 – Linq Inner Join query.
  6. Linq Chapter 6 – Linq Distinct list.
  7. Linq Chapter 7 – Linq OfType Method.

C# Program ToDictionary.

void Main()
{

     var results = new[] { new {Name = "Asp.net", Points = 50}, 
                                new {Name = "C#.net"  , Points = 40}, 
                                new {Name = "VB.net.net"  , Points = 60}, 
                                new {Name = "WCF"  , Points = 80}, 
                                new {Name = "OOPs", Points = 45} 
                            }; 
  
    var resultsDict = results.ToDictionary(x => x.Name); 
  
    Console.WriteLine("Points Achived in : {0}", resultsDict["Asp.net"]); 
}

Output
Points Achieved in : { Name = Asp.net, Points = 50 }.

VB.net ToDirectory

Here we will see how to use ToDictionary method to convert list into Dictionary and search the content using Vb.net program.

Private Sub Main()

	Dim results = New () {New With { _
		Key .Name = "Asp.net", _
		Key .Points = 50 _
	}, New With { _
		Key .Name = "C#.net", _
		Key .Points = 40 _
	}, New With { _
		Key .Name = "VB.net.net", _
		Key .Points = 60 _
	}, New With { _
		Key .Name = "WCF", _
		Key .Points = 80 _
	}, New With { _
		Key .Name = "OOPs", _
		Key .Points = 45 _
	}}

	Dim resultsDict = results.ToDictionary(Function(x) x.Name)

	Console.WriteLine("Points Achived in : {0}", resultsDict("Asp.net"))
End Sub

Tags:

C# ArrayList Search using Linq Extension OfType MethodLinq Group By Multiple ColumnsLinq Split String To ListLearn Linq Step By StepLinq Inner JoinHow to select multiple columns in Linq- C#.net VB.net codeLinq Distinct ListLinq Union and intersect ExampleLinq Get Duplicate Count Of Words From StringLinq to SqlLinq Array Order-By

Author

My name is Satalaj, but people call me Sat. Here is my homepage: . I live in Pune, PN and work as a Software Engineer. I'm former MVP in ASP.net year 2010.
Disclaimer: Views or opinion expressed here are my personal research and it has nothing to do with my employer. You are free to use the code, ideas/hints in your projects. However, you should not copy and paste my original content to other web sites. Feel free to copy or extend the code.
If you want to fight with me, this website is not for you.
 

I'm Satalaj.