I don't understand why there isn't a native function to do this. Suppose that I create the following class:
public class Student {
public string Name {get; set;}
public override int GetHashCode() {
return(Name.GetHashCode());
}
}
Afterwards, I create a HashSet containing a number of students. Now I want to get a student from the HashSet using his name, which is also the hash code used, without enumeration. Is this possible? If it is, how would I accomplish this? Since the name of the student is used as the hash code, this should be possible with an O(1) operation, right?
Dictionary<string,Student>and you can get the value asmyDictionary["name"]