Do you really need SortedSet
which is red-black tree? If you don't need sorting, you shouldn't use it. Have you considered HashSet
or Dictionary
instead which is more suitable (fast) for getting item by key?
In your case you probably need to create Dictionary
instance with key equals to person name, i.e.:
Dictionary<string, Person> list;
Then you can get person by it's name, complexity is O(1)
if(list.ContainsKey(line[0]))
{
list[line[0]]...
}
or even better:
Person p;
if(list.TryGetValue(line[0], out p))
{
p...
)