2010-03-31 25 views
3

可能重复:
C# - Is there a better alternative than this to ‘switch on type’?C# - 哪个是'开启类型'的最佳选择?

1) http://channel9.msdn.com/forums/TechOff/411739-switch-objectGetType-/?CommentID=411995

2) http://blogs.msdn.com/jaredpar/archive/2008/05/16/switching-on-types.aspx

3) 还是有更好的方法。 ...?

请注意速度和阅读代码的难易程度。

+0

也看到 http://stackoverflow.com/questions/156467/switch-pattern-matching-idea http://stackoverflow.com/questions/7252186/switch-case-on-type-c-sharp http://stackoverflow.com/questions/7542793/how-to-use-switch-case-on-a-type http://stackoverflow.com/questions/4478464/c-sharp-switch-on-type http://stackoverflow.com/questions/298976/c-sharp-is-there-a-better-alternative-than-this-to-switch-on-type – Mikhail 2012-05-01 11:58:13

+0

和 http://stackoverflow.com/questions/ 94305 /什么是更快的开关在字符串或其他类型上 http://stackoverflow.com/questions/6304815/why-is-this-switch-on-type-case-considered-令人困惑的 http://stackoverflow.com/ques tions/5947343 /如何在可能的对象类型之间切换 http://stackoverflow.com/questions/10115028/best-way-to-switch-behavior-based-on-type – Mikhail 2012-05-01 11:58:26

回答

1

在所有建议我更喜欢第二选项。一般而言,我更喜欢double dispatch而不愿意使用Type

相关问题