List operator == In the C# Language Specification Version 4

前端 未结 2 2010
萌比男神i
萌比男神i 2020-12-20 11:33

In the C# Language Specification Version 4, 1.6.7.5 Operators is information about List operators: == and !=. But I can\'t fi

2条回答
  •  萌比男神i
    2020-12-20 11:51

    The spec is indeed correct, although confusing. The spec defines a class called List (poor naming choice).

    The following table shows a generic class called List, which implements a growable list of objects. The class contains several examples of the most common kinds of function members.

    This class can be seen in the spec at section 1.6.7. The Equals operator is overloaded and matches the output explained above. Perhaps a better name should have been chosen for that class.

    static bool Equals(List a, List b) {
        if (a == null) return b == null;
        if (b == null || a.count != b.count) return false;
        for (int i = 0; i < a.count; i++) {
            if (!object.Equals(a.items[i], b.items[i])) {
                return false;
            }
        }
      return true;
    }
    

提交回复
热议问题