Cast a hashtable.Keys into List or other IEnumerable

后端 未结 6 723
伪装坚强ぢ
伪装坚强ぢ 2020-12-31 16:40

I know, I have other options, e.g. I could maintain a separate list of keys. Please don\'t suggest other options. I simply want to know if I can pull this off. Please don\'t

6条回答
  •  清歌不尽
    2020-12-31 17:10

    Your foreach loop will throw an InvalidCastException if the Keys collection doesn't contain an int.

    The cast to List fails because the compiler can't convert a non-generic ICollection to a specific ICollection

提交回复
热议问题