如何将IComparer传递给.net中的SortedDictionary?

时间:2014-04-30 12:31:10

标签: .net

比较课程:

#pragma strict
public class TEffectComparator implements IComparer
{
    public function TEffectComparator()
    {

    }
    public static function Compare (f,s)
    {
        if(!f||!s)
            return 0;
        var fe=get_var(f,"essential");
        var se=get_var(s,"essential");
        var t:boolean=op_GreaterThan((fe as TEssential),(se as TEssential));
        if(t==true)
            return 1;
        return -1;
    }
}

这会产生错误:

var s:SortedDictionary.<TEssential,Object> = new SortedDictionary.<TEssential,Object> (new TEffectComparator());
  

Assets / effects / terminal / apply_movement.js(21,32):BCE0004:不明确的引用'构造函数':System.Collections.Generic.SortedDictionary..constructor(System.Collections.Generic.IDictionary。),System.Collections .Generic.SortedDictionary..constructor(System.Collections.Generic.IComparer)。

在这种情况下,似乎我的ide无法区分IComparer和IDictionary。为什么呢?

#pragma strict
public class TEffectComparator implements IComparer.<TEssential>
{
    public function TEffectComparator()
    {

    }
    public static function Compare (f,s)
    {
        if(!f||!s)
            return 0;
        var fe=get_var(f,"essential");
        var se=get_var(s,"essential");
        var t:boolean=op_GreaterThan((fe as TEssential),(se as TEssential));
        if(t==true)
            return 1;
        return -1;
    }
}

抛出

  

Assets / scripts / TEffectComparator.js(2,43):BCE0138:   'System.Collections.IComparer'不是通用定义。

1 个答案:

答案 0 :(得分:1)

正如Lee所说, System.Collections.Generic.IComparer&lt;应该使用T&gt; ,而不是 System.Collections.IComparer