Skip to content

Instantly share code, notes, and snippets.

@FurkanKozen
Created May 13, 2020 21:52
Show Gist options
  • Save FurkanKozen/520fa83aec74b63665e5adce966a9c53 to your computer and use it in GitHub Desktop.
Save FurkanKozen/520fa83aec74b63665e5adce966a9c53 to your computer and use it in GitHub Desktop.
Finding the key by its value
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
public static void Main(string[] args)
{
var dict = new Dictionary<string, int>();
dict.Add("A", 25);
dict.Add("B", 35);
dict.Add("C", 45);
var key = dict.Single(kv => kv.Value == 35).Key;
Console.WriteLine(key);
Console.ReadKey();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment