[펌] Get dictionary key by value
How do I get a Dictionary key by value in C#?
Dictionary<string, string> types = new Dictionary<string, string>()
{
{"1", "one"},
{"2", "two"},
{"3", "three"}
};
[Answer]
Values do not necessarily have to be unique, so you have to do a lookup. You can do something like this:
var myKey = types.FirstOrDefault(x => x.Value == "one").Key;
If values are unique and are inserted less frequently than read, then create an inverse dictionary where values are keys and keys are values.
[출처] https://stackoverflow.com/questions/2444033/get-dictionary-key-by-value
Get dictionary key by value
How do I get a Dictionary key by value in C#? Dictionary<string, string> types = new Dictionary<string, string>() { {"1", "one"}, {"2", "two&q...
stackoverflow.com
[참조] https://miuna3.tistory.com/81
C# 사전 Dictionary의 Value 값으로 Key 찾기
Dictionary Dic = new Dictionary() { {"1", "Mon"}, {"2", "Tue"}, {"3", "Thu"} };사전이 위와같이 있다고 가정하자. 현재 Dic 의 키 "1" 은 값 "Mon"을 가지고있다. "Mon"으로 키 "1"을 찾고자 할 때에는 아래와 같이 사용하
miuna3.tistory.com
'Programming > C#' 카테고리의 다른 글
[링크][C#] 양력 <-> 음력 변환 (0) | 2024.11.25 |
---|---|
[Exception] ArgumentOutOfRangeException: Year, Month, and Day parameters describe an un-representable DateTime. (0) | 2024.02.29 |
[링크] C# 특정 문자열 삭제, 특정 문자열 교체 Regex.Replace (0) | 2023.11.08 |
[펌] c# String.Format && string 자릿수 맞추기 (0) | 2023.09.18 |
[링크] [C#][.NET framework] Directory.GetFiles() 로 여러 확장자 필터링 하기 (0) | 2023.02.21 |