类库和命名空间有什么区别? [英] What is the difference between a class library and a namespace?

查看:76
本文介绍了类库和命名空间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

类库和命名空间之间的实际区别是什么?我知道两者都用于将类、命名空间等组合在一起.谁能告诉我应该在哪种情况下使用类库以及何时创建新的命名空间.

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 use a class library and when to go for creating a new namespace.

推荐答案

命名空间为类提供了概念上的分离,类库提供了物理分离(在 windows 中认为是独立的 dll).

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.

想象一下,创建一个 Windows 应用程序,您将 UI 和实现类(类库)拆分为 2 个不同的项目.然后你发现你需要有一个同样东西的网络版本.您只需导入您从 Windows 应用程序创建的类库,您就可以使用所有实现,只需专注于 Web UI.

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.

如果你在一个项目中创建了整个 Windows 应用程序,使用命名空间来分隔它们,那么这样做会很棘手 &乱.(试过导入 exe 吗?)

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

这篇关于类库和命名空间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆