Right way to implement GetHashCode for this struct

前端 未结 7 1871
庸人自扰
庸人自扰 2021-02-13 06:13

I want to use a date range (from one date to another date) as a key for a dictionary, so I wrote my own struct:

   struct DateRange
   {
      public DateTime St         


        
7条回答
  •  时光说笑
    2021-02-13 06:49

    Just as it might help someone in the future that uses visual studio pro (not sure if this also exist in community edition)

    • Select the desired properties (in your case all)
    • Press refacoring (CTRL + . or right click "Quick actions an refactorings")
    • Now you can select to implement Equals or GetHashcode (and probably it always takes the best known MS way to do it)

提交回复
热议问题