i'm fairly new to c# and i have a problem. I've filled 2 SortedSet's with a lot(thousands) of custom objects, and i am trying to make a function that quickly accesses the other SortedSet, without iterating over them(iterating takes too much time, about 40 sec.). i've sorted the set by name, and then by expansion using an interface:
public int CompareTo(card other)
{
if (string.Compare(this.name,other.name)>0)
return 1;
if (string.Compare(this.name, other.name) < 0)
return -1;
else if (string.Compare(this.expansion, other.expansion) > 0)
return 1;
else if (string.Compare(this.expansion, other.expansion) < 0)
return -1;
else
return 0;
} // in my obj declaration.
//and the following for declaring the sortedset:
public SortedSet<card> MM = new SortedSet<card>();
public SortedSet<card> MMother = new SortedSet<card>();
//i can do the following:
int counter=0;
foreach (card thing in MM) //took only .7 seconds
{
if(thing.IsProperSubsetOf(MMother))
counter++;
}
this works fine but, Since the objects do not only have a name and expansion, but also other attributes like,price= 10 , owner = "jack" etc etc etc. id like to access those, without iteration. something like:
int price = (MMother.matches(card)-->return price)
but i dont know how to do this. Any tips?