IComparable <string>实现 - 无法访问字符串的长度

时间:2018-04-24 13:19:44

标签: c# collections

item.stateChanges(["child_added"]).subscribe((data) => {
     var items = data.payload.val();
})

该代码不起作用,因为&#34; MyComparer&#34;不包含&#34;长度&#34;的定义,那么如何访问长度?

1 个答案:

答案 0 :(得分:2)

您正在实施错误的界面。您需要IComparer<string>代替:

class MyComparer : IComparer<string>
{
    public int Compare(string x, string y)
    {
        int diff = x.Length - y.Length;

    }
}