471,356 Members | 1,656 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

Class vs. 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?

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
Aug 12 '08 #1
10 1988
Paolo wrote:
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
You can create a new project in the solution and create one or more
classes in it. This will then be compiled into a separate dll. To use
the classes from the application you need to add a reference to the project.

To use the classes in another solution, you can either add the project
to the solution and add a reference to the project, or add a reference
to the compiled dll file.

(Of course you can also develop the project separately in it's own
solution.)

If a class is in a different namespace (which it usually would be if
it's in a separate project), you either can use a using directive to
import the namespace or specify the full class name (i.e.
namespace.classname) everytime you use the class.

--
Göran Andersson
_____
http://www.guffa.com
Aug 12 '08 #2
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...
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

Aug 12 '08 #3
Paolo wrote:
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?
Not really.

The stuff in the DLL is made available not included.
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?
You put compile one or more classes to a DLL. Good.

Arne
Aug 13 '08 #4
On Aug 13, 3:09*am, Paolo <Pa...@discussions.microsoft.comwrote:
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
As I see in your case, go for a DLL version of implementation. I see
that as a best practice.

-Cnu
Aug 13 '08 #5
Peter: thanks for the clear explanation, which clarifies my supplementary
questions regarding namespaces and adding references.

As I understand it, if I choose a 'Class Library' as my project this gets
compiles into a DLL.

"Peter Rilling" wrote:
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...
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


Aug 13 '08 #6
Goran: thanks for the clarification.

"Göran Andersson" wrote:
Paolo wrote:
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

You can create a new project in the solution and create one or more
classes in it. This will then be compiled into a separate dll. To use
the classes from the application you need to add a reference to the project.

To use the classes in another solution, you can either add the project
to the solution and add a reference to the project, or add a reference
to the compiled dll file.

(Of course you can also develop the project separately in it's own
solution.)

If a class is in a different namespace (which it usually would be if
it's in a separate project), you either can use a using directive to
import the namespace or specify the full class name (i.e.
namespace.classname) everytime you use the class.

--
Göran Andersson
_____
http://www.guffa.com
Aug 13 '08 #7
Arne:
If I create a DLL do I include these functions by adding it as a reference
in my projects?

Not really.
How does the application 'know' about my functions?

"Arne Vajhøj" wrote:
Paolo wrote:
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?

Not really.

The stuff in the DLL is made available not included.
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?

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

Arne
Aug 13 '08 #8
Cnu: VSC# Express allows a 'Class Library' project to be created - there is
no separate 'Create DLL' project type, so I presume a Class Library will be
compiled to a DLL.

Thanks

"Duggi" wrote:
On Aug 13, 3:09 am, Paolo <Pa...@discussions.microsoft.comwrote:
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

As I see in your case, go for a DLL version of implementation. I see
that as a best practice.

-Cnu
Aug 13 '08 #9
Peter: a further question. Do I have to make the member methods of my
'Utilities' class/DLL public so that applications which use them can 'see'
them?

"Peter Rilling" wrote:
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...
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


Aug 13 '08 #10
Paolo wrote:
>>If I create a DLL do I include these functions by adding it as a reference
in my projects?
Not really.

How does the application 'know' about my functions?
Adding a reference does just that add a reference - it does not
include the functions.

Arne
Aug 13 '08 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Fernando Rodriguez | last post: by
18 posts views Thread by John M. Gabriele | last post: by
13 posts views Thread by Bryan Parkoff | last post: by
8 posts views Thread by Bryan Parkoff | last post: by
21 posts views Thread by Jon Slaughter | last post: by
5 posts views Thread by Andy | last post: by
3 posts views Thread by Hamilton Woods | last post: by
reply views Thread by emin.shopper | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.