Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Find key in dictionary list

Posted on 2016-10-03
6
Medium Priority
?
58 Views
Last Modified: 2016-10-03
Hello,
How to find a whether value exists in dictionarylist and if exists then get the key of it ?

is it  containsVALUE? or        .TryGetValue?

Cheers
0
Comment
Question by:RIAS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 52

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 41826091
HI,

pls try
	Dictionary<string, string> values =
	    new Dictionary<string, string>();

	values.Add("test1", "found1");
	values.Add("Test2", "found2");
	if (values.TryGetValue("test1", out Result)) 
	{
	    Console.WriteLine(Result);
	}

Open in new window

0
 

Author Comment

by:RIAS
ID: 41826107
Rgonzo1971,
Cheers mate!

Is there a reverese vway to do it

Have value and get key ?
0
 
LVL 52

Expert Comment

by:Rgonzo1971
ID: 41826109
Using Linq

Console.WriteLine (values.FirstOrDefault (x => x.Value == "Result").Key);
0
Major Serverless Shift

Comparison of major players like AWS, Microsoft Azure, IBM Bluemix, and Google Cloud Platform

 

Author Comment

by:RIAS
ID: 41826111
I am using vb.net 2015
0
 

Author Comment

by:RIAS
ID: 41826123
Rgonzo1971,
Found your solution on some other expeerts exchange question:

Dim keys = reportdays.Where(Function(pair) pair.Value =  date1).Select(Function(pair) pair.Key).ToList()
If keys.Count > 0 Then
    Console.WriteLine(String.Format("key: {0}", keys(0)))
End If
0
 

Author Closing Comment

by:RIAS
ID: 41826124
Cheers!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question