0

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?

Roland
  • 71
  • 6
  • Do you really need sorting? If not, you can just use HashSet; Take a look at http://stackoverflow.com/questions/19556966/c-sharp-sortedset-how-to-get-an-element-out – undefined Apr 04 '15 at 11:24
  • I just need to sort it when i write stuff to disk. i can sort then! i changed the code to dictionary using name+expansion as key.. works like a charm now..thx.. – Roland Apr 05 '15 at 06:35

0 Answers0