Linked Questions

5 votes
4 answers
39k views

Get key by value in hash table c# [duplicate]

I want to get the key of my value but this does not Possible in Hashtable Is there data stretcher to do this ?? Hashtable x = new Hashtable(); x.Add("1", "10"); x.Add("2", "20"); x....
motaz99's user avatar
  • 501
2 votes
0 answers
1k views

Force all values in a dictionary to be unique? [duplicate]

I need to maintain a mapping between enum values, and a multi-value type (name+number). e.g. ABC : {"john", 123} DEF : {"paul", 234} GHI : {"ringo", 345} I planned to do this using a Dictionary of ...
Mr. Boy's user avatar
  • 64.5k
963 votes
37 answers
832k views

String representation of an Enum

I have the following enumeration: public enum AuthenticationMethod { FORMS = 1, WINDOWSAUTHENTICATION = 2, SINGLESIGNON = 3 } The problem however is that I need the word "FORMS" ...
user29964's user avatar
  • 16k
522 votes
12 answers
920k views

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"...
loviji's user avatar
  • 13.1k
77 votes
6 answers
142k views

Remove Item in Dictionary based on Value

I have a Dictionary<string, string>. I need to look within that dictionary to see if a value exists based on input from somewhere else and if it exists remove it. ContainsValue just says true/...
Jon's user avatar
  • 40.2k
26 votes
5 answers
77k views

Get Dictionary key by using the dictionary value

How to get the dictionary key by using the dictionary value? when getting the value using the key its like this: Dictionary<int, string> dic = new Dictionary<int, string>(); dic.Add(1, "...
Rye's user avatar
  • 2,321
38 votes
5 answers
38k views

What is an alternative to Dictionaries in C# that allows for duplicate keys?

I have a method that returns groups of technicians who have worked on certain projects, for example: project 1 | John project 1 | Tim project 2 | John project 2 | Dave I originally tried to create a ...
AdamMc331's user avatar
  • 16.7k
24 votes
3 answers
88k views

LINQ: Getting Keys for a given list of Values from Dictionary and vice versa

I have the following structure in my code Dictionary<TKeys, TValues> data;. I run some LINQ queries on both data types and often need to switch between Keys and Values. What is the best way to ...
Alexander Galkin's user avatar
24 votes
3 answers
21k views

Reverse many-to-many Dictionary<key, List<value>>

Actually my previous question got me thinking and I realized that reversing a Dictionary is not trivial. What is the most elegant and readable way to do it? Same scenario student Many to Many with ...
roundcrisis's user avatar
  • 17.9k
16 votes
4 answers
7k views

C#: Is a SortedDictionary sorted when you enumerate over it?

A SorteDictionary is according to MSDN sorted on the key. Does that mean that you can be sure that it will be sorted when you enumerate it in a foreach? Or does it just mean that the SortedDictionary ...
Svish's user avatar
  • 159k
9 votes
6 answers
23k views

how to use dictionary two way in c#

public static Dictionary<int, string> dic = new Dictionary<int, string>() { {1,"anystring1"}, {2,"anystring2"}}; I need to use this string str= dic[1]; // it is ...
ebattulga's user avatar
  • 11.1k
3 votes
4 answers
10k views

.Net Dictionary with forced unique values

Is it possible to force a Dictionary to have unique values? See the following example. Dictionary<string, string> types = new Dictionary<string, string>() { {"1", "one"}, {...
JBone's user avatar
  • 3,223
23 votes
1 answer
23k views

Bi-directional dictionary? [duplicate]

I have two sets of objects where in some cases the first set will be used as keys for the other set, and in other cases the second set will be used as keys for the first. In addition there must be no ...
Svish's user avatar
  • 159k
2 votes
4 answers
5k views

Getting key from value in .Net collection

I am using a StringDictionary to store key value pairs. I need to use the keys and values interchangeably i.e. I should be able to get the key from the value as in my case the values will be distinct. ...
Rashmi Pandit's user avatar
1 vote
7 answers
4k views

Get the next KeyValuePair<,> from a Dictionary<,> without index

Is is possible to obtain the position of a given KeyValuePair<,> within a Dictionary<,>, or the next object, without having an index or alike? For instance, assume that I have the ...
auhmaan's user avatar
  • 727

15 30 50 per page