HashSet does not require IComparer<T> - it needs IEqualityComparer<T> , for example
public class SynonymComparer : IEqualityComparer<Synonym> { public bool Equals(Synonym one, Synonym two) {
However, your current code only compiles because you are creating a set of comparators, not a set of synonyms.
Also, I don't think you really need a kit. It seems to me that you need a dictionary or search so that you can find synonyms for this name:
public class SynonymManager { private readonly IDictionary<string, Synonym> synonyms = new Dictionary<string, Synonym>(); private void Add(Synonym synonym) {
Please note that in the above code there are some questions about how you want it to behave in different cases. You need to pinpoint what you want.
EDIT: if you want to store multiple stocks for one synonym, you really want Lookup<string, Stock> , but that is immutable. You should probably store Dictionary<string, List<Stock>> ; stock list for each row.
In terms of not throwing an error from Find you should look at Dictionary.TryGetValue , which does not throw an exception if the key is not found (and also returns if the key was found); the displayed value is "returned" in the output parameter.
Jon skeet
source share