ICollection.Contains on custom types

后端 未结 4 818
旧时难觅i
旧时难觅i 2021-01-12 02:19

If I have a (reference - does it matter?) type MyType which does not override the Equals method, what heuristics will be used when determining if an IC

4条回答
  •  死守一世寂寞
    2021-01-12 03:00

    It's not defined by ICollection- different implementations can use different methods. From MSDN:

    Implementations can vary in how they determine equality of objects; for example, List uses Comparer.Default, whereas Dictionary allows the user to specify the IComparer implementation to use for comparing keys

    In most cases it will just compare the references, but you should check the documentation for the specific ICollection you are using.

提交回复
热议问题