类与DLL [英] Class vs. DLL

查看:92
本文介绍了类与DLL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用控制台应用程序学习C#。我想开发一些实用程序

函数(包含一些Console类方法),这样我就可以为我编写的任何程序提供




如果我创建了一个DLL,我是否可以通过在项目中添加它作为参考来包含这些函数




如果我创建了一个类,我是否添加''using''指令来包含它们?


这两种方法都有任何优点/缺点吗?


谢谢

Learning C# using Console applications. I want to develop some utility
functions (wrapping up some of the Console class methods) so that I can have
them available for any program that I write.

If I create a DLL do I include these functions by adding it as a reference
in my projects?

If I create a Class do I add the ''using'' directive to include them?

Are there any pros/cons with respect to either approach?

Thanks

推荐答案

Paolo写道:
Paolo wrote:

使用控制台应用程序学习C# 。我想开发一些实用程序

函数(包含一些Console类方法),这样我就可以为我编写的任何程序提供




如果我创建了一个DLL,我是否可以通过在项目中添加它作为参考来包含这些函数




如果我创建了一个类,我是否添加''using''指令来包含它们?


这两种方法都有任何优点/缺点吗?


谢谢
Learning C# using Console applications. I want to develop some utility
functions (wrapping up some of the Console class methods) so that I can have
them available for any program that I write.

If I create a DLL do I include these functions by adding it as a reference
in my projects?

If I create a Class do I add the ''using'' directive to include them?

Are there any pros/cons with respect to either approach?

Thanks



您可以在解决方案中创建一个新项目,并在其中创建一个或多个

类。然后将其编译为单独的dll。要使用

应用程序中的类,您需要添加对项目的引用。


要在其他解决方案中使用这些类,您可以添加项目

到解决方案并添加对项目的引用,或者在编译的dll文件中添加一个引用




(当然你也可以在它自己的

解决方案中单独开发项目。)


如果一个类在不同的命名空间(它是通常情况下,如果它是在一个单独的项目中,你可以使用using指令来导入命名空间或指定完整的类名(即

namespace.classname)每次使用该课程。


-

G ??跑Andersson

_____
http://www.guffa.com


正如您所做的那样,移动常见的

功能总是一个好习惯远离应用程序,以便可以共享。


现在对你的课程进行一些澄清。与dll相对题。一个DLL是类的容器,因此当你创建一个类时,它会被编译成一个DLL / Assembly中的
。您只需创建另一个库即可。项目和

从控制台项目中移动您的类/代码。一旦完成,那么是的,你需要在你的控制台应用程序中添加对该程序集的引用。


关于你是否使用使用语句取决于您的命名空间。如果

您选择为您的库代码提供与您的

应用程序不同的命名空间(您可能希望这样做,因为此代码将是

共享)然后你还需要在任何引用你的实用程序类的应用程序

文件中添加一个using指令。

" Paolo" < Pa *** @ discussion.microsoft.com写信息

news:96 ************************* ********* @ microsof t.com ...
As you are trying to do, it is always a good practice to move common
functionality away from the application so that it can be shared.

Now some clarification regarding your "class" vs. "dll" question. A DLL is
a container for classes, therefore when you create a class, it is compiled
into a DLL/Assembly. You can simply create another "library" project and
move your classes/code from the console project. Once done, then yes, you
have to add a reference to that assembly in your console application.

As to whether you use a "using" statement depends on your namespaces. If
your choose to give your library code a different namespace from your
application (which you will probably want to do since this code will be
shared) then you will also need to add a "using"directive in any application
file that references your utility classes.
"Paolo" <Pa***@discussions.microsoft.comwrote in message
news:96**********************************@microsof t.com...

使用控制台应用程序学习C#。我想开发一些实用工具

函数(包含一些Console类方法),这样我就可以



它们可用于任何我编写的程序。


如果我创建了一个DLL,我是否可以在项目中添加它作为参考

来包含这些函数?


如果我创建一个类,我是否添加''using''指令来包含它们?


这两种方法都有任何优点/缺点吗?


谢谢
Learning C# using Console applications. I want to develop some utility
functions (wrapping up some of the Console class methods) so that I can
have
them available for any program that I write.

If I create a DLL do I include these functions by adding it as a reference
in my projects?

If I create a Class do I add the ''using'' directive to include them?

Are there any pros/cons with respect to either approach?

Thanks



Paolo写道:
Paolo wrote:

使用控制台应用程序学习C#。我想开发一些实用程序

函数(包含一些Console类方法),这样我就可以为我编写的任何程序提供




如果我创建了一个DLL,我是否可以在项目中添加它作为参考

来包含这些函数?
Learning C# using Console applications. I want to develop some utility
functions (wrapping up some of the Console class methods) so that I can have
them available for any program that I write.

If I create a DLL do I include these functions by adding it as a reference
in my projects?



不是真的。


DLL中的内容不包括在内。

Not really.

The stuff in the DLL is made available not included.


如果我创建一个类,我是否添加''using''指令来包含它们?
If I create a Class do I add the ''using'' directive to include them?



不是真的。


使用允许你引用没有命名空间的类名。

Not really.

The using allows you to refer to class names without their namespace.


这两种方法都有任何优点/缺点吗?
Are there any pros/cons with respect to either approach?



您将一个或多个类编译到DLL中。好。


Arne

You put compile one or more classes to a DLL. Good.

Arne


这篇关于类与DLL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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