Using GetHashCode for getting Enum int value

后端 未结 7 1230
北海茫月
北海茫月 2020-12-03 07:20

I have an enum

public enum INFLOW_SEARCH_ON
{
  ON_ENTITY_HANDLE = 0,         
  ON_LABEL = 1,                 
  ON_NODE_HANDLE = 2            
} // enum I         


        
7条回答
  •  猫巷女王i
    2020-12-03 07:38

    Others have said why casting to int is better.

    Another reason to not use GetHashCode is performance. It causes boxing. In my quick tests, GetHashCode was about 50 times slower (if it matters).

提交回复
热议问题