Compare two System.Enum of type T

后端 未结 2 1536
醉话见心
醉话见心 2021-01-17 23:26

I am pretty close to understand Generics now (I think).
However, just figured that System.Enum is not easy to implement as a generic type. I have this class:

<         


        
2条回答
  •  执笔经年
    2021-01-18 00:30

    Instead of the impossible

    button.Identifier == Identifier
    

    you should use

    EqualityComparer.Default.Equals(button.Identifier, Identifier)
    

    This avoids boxing the value into an object box (or IComparable box).

提交回复
热议问题