Testing if an Object is a Dictionary in C#

后端 未结 7 1181
傲寒
傲寒 2020-12-06 10:21

Is there a way to test if an object is a dictionary?

In a method I\'m trying to get a value from a selected item in a list box. In some circumstances, the list box

7条回答
  •  一向
    一向 (楼主)
    2020-12-06 11:07

    I believe a warning is at place.

    When you're testing if an object 'is a' something this or that, you're reimplementing (part of) the type system. The first 'is a' is often swiftly followed by a second one, and soon your code is full of type checks, which ought to be very well handled by the type system - at least in an object oriented design.

    Of course, I know nothing of the context of the question. I do know a 2000 line file in our own codebase that handles 50 different object to String conversions... :(

提交回复
热议问题