Tool to refactor C# var to explicit type

前端 未结 7 650
陌清茗
陌清茗 2020-12-03 17:15

Our coding standards ask that we minimise the use of C# var (suggests limiting it\'s use to being in conjunction with Linq). However there are times when using generics wher

7条回答
  •  再見小時候
    2020-12-03 17:37

    @Adam - you can't declare a class here, since that won't be what comes back from an IDictionary<,>.GetEnumerator() - however, you can alias via using:

    using InnerPair = System.Collections.Generic.KeyValuePair>;
    

    Then:

    foreach(InnerPair pair in dict) {...}
    

    This is just a type alias, so works fine.

提交回复
热议问题