What is the difference between a class library and a namespace?

前端 未结 2 730
轻奢々
轻奢々 2021-02-06 02:21

What is the actual difference between class library and a namespace? I know both are used to group together classes, namespace etc. Can anyone tell in which scenario should I us

2条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-06 02:57

    Namespaces provide a notional separation for classes, class libraries provide a physical separation (in windows think a standalone dll).

    Class libraries are useful for when you want to wrap up functionality that can be shared with other projects.

    Imagine creating a windows application where you split the UI and the implementation classes (class library) into 2 different projects. Then you find you need to have a web version of the same thing. You can just import the class library you created from the windows application and you have all your implementation available to you and just focus on the web UI.

    If you'd created the whole windows app in one project using namespaces to seperate them, doing that would be tricky & messy. (ever tried importing an exe?)

    It is worth pointing out that class libraries will themselves likely use namespaces to provide further notional separation to the classes within them

提交回复
热议问题