如何访问Sorted Set元素,而不进行迭代?

时间:2015-04-04 11:17:50

标签: c# information-retrieval sortedset custom-object

我对c#相当新,我有一个问题。我已经为2个SortedSet填充了大量(数千个)自定义对象,我正在尝试创建一个快速访问其他SortedSet的函数,而不会迭代它们(迭代需要花费太多时间,大约40个秒)。 我按名称对集合进行了排序,然后使用界面进行扩展:

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++;
        }

这个工作正常,但是,由于对象不仅有名称和扩展,还有其他属性,例如,price = 10,owner =&#34; jack&#34;等等等id就像访问那些,没有迭代。类似的东西:

  

int price =(MMother.matches(card) - &gt;返回价格)

但我不知道该怎么做。有小费吗?

0 个答案:

没有答案