Why is the use of reflection in .NET recommended?

后端 未结 9 674
再見小時候
再見小時候 2020-11-30 22:25

Is it definitely a good practice to use it?

What are some possible situations in a project that need reflection?

9条回答
  •  情书的邮戳
    2020-11-30 22:55

    Coming from C++ and having needed some simple class hierarchies, I can say that the is keyword is invaluable!

    class MenuItem : Item { }
    
    foreach(Item items in parent.ChildItems) {
        if (item is MenuItem) { /* handle differently */ }
    }
    

    P.S. Isn't reflection slightly expensive, btw?

提交回复
热议问题