List.Contains and T[].Contains behaving differently

前端 未结 3 965
情歌与酒
情歌与酒 2021-02-12 14:25

Say I have this class:

public class Animal : IEquatable
{
    public string Name { get; set; }

    public bool Equals(Animal other)
    {
                 


        
3条回答
  •  眼角桃花
    2021-02-12 14:54

    Arrays does implement the generic Interfaces IList, ICollection and IEnumerable but the implemeneation is provided at runtime and therefore are not visible to the documentation build tools (That is why you don't see ICollection.Contains in the msdn documentation of Array).

    I suspect that the runtime implementation just calls the non generic IList.Contains(object) that the array already has.
    And therefor the non generic Equals method in your class is called.

提交回复
热议问题