CodeDocu.com

 

 

How do you find a value in a dictionary in C #?

A dictionary consists of key-value elements, that is, there are always pair entries with a key and a value such as <"ABC1000", "Maier">

Settings are for example a dictionary.

 

The dictionary offers as a simple search only the search for the key key or a combination of key and value.

But if you want to search for a value, then you have to search as follows

var Treffer= dict.FirstOrDefault(x => x.Value.ToString() == suchtext);

 

Since the found element is a KeyValuePair, you can not compare it directly to zero. Instead, you have to compare the internal key to zero.

if (find_Item.Key==null) return;

 

Code example for finding a value in the settings as a dictionary and then comparing if there is a hit below the values.

//-< check exists >-

System.Collections.Generic.KeyValuePair<string, object> find_Item = ApplicationData.Current.LocalSettings.Containers["Used_Folders"].Values.FirstOrDefault(x => x.Value.ToString() == sFolder);

if (find_Item.Key==null)

{

    return;

}

//-</ check exists >-

 

 

C #: find value in a dictionary and compare

 


Software Entwicklung Stuttgart NĂ¼rtingen
Suche Projekte C#, WPF, Windows App,ASP.Net, vb.Net, WinForms, SQL Server, Access, Excel