Resharper thinks that typecast is redundant, but w

2019-05-12 17:41发布

Iterating JsonData through foreach fetches IDictionary enumerator instead of IList one.

foreach (var jsonEntry in jsonData)

This causes my code to throw an error.

InvalidOperationException: Instance of JsonData is not a dictionary
LitJson.JsonData.EnsureDictionary ()
LitJson.JsonData.System.Collections.Specialized.IOrderedDictionary.GetEnumerator ()
LitJson.JsonData.System.Collections.IDictionary.GetEnumerator ()

Casting the object to IList causes Resharper to issue a warning "Type cast is redundant."

foreach (var jsonEntry in jsonData as IList)

Why does Resharper think the cast is redundant ?

1条回答
神经病院院长
2楼-- · 2019-05-12 18:19

Why does Resharper think the cast is redundant ?

If you think this way:

IList is a ICollection and IDictionary is also a ICollection because both of them implement 'ICollection', Resharper's warning should become clear.

查看更多
登录 后发表回答