Are extension methods an object-oriented feature of C#?

前端 未结 6 1319
迷失自我
迷失自我 2020-12-19 16:48

Do extension methods follow the object-oriented paradigm in C#?

Is it a good practice to use extension methods?

In the software development lifecycle how s

6条回答
  •  情歌与酒
    2020-12-19 17:37

    Extension methods are just a language feature. They work on object instances and are very nice tool.

    Consider them as a different way to extend class functionality. You can add new functionality to a class:

    • By adding a partial class declaration. The class then instantly gets a bunch of new methods and properties.

    • By including a namespace with your extension methods holder class. The class then gets a bunch of new methods again.

    Rather an organizational / language feature. Does not break object-oriented concept in any way. Just as header/source file division in C/C++ has nothing to do with object-orientation, just a language/framework feature.

提交回复
热议问题