Can someone clarify for me what the difference is between class libraries and individual classes? What are the advantages/disadvantages of each and when to write each? Thanks
-
3It's quite the same as it is for book and library that contains many books. Library is used when you need to store more than one of your books, it also allows to group books by certain criteria... There's no such thing as 'individual class' because classes are defined in `namespace` and this namespace is located inside `assembly` and so on... Class has to be somewhere so it is always part of some bigger data structure – Fabjan Nov 25 '15 at 16:15
-
One is a file, the other is a project type. One can't exist without the other. Every project has classes, some are executable, some are libraries. – Ron Beyer Nov 25 '15 at 16:15
1 Answers
It's quite the same as it is for book and library that contains many books.
Library is used when you need to store more than one of your books, it also allows to group books by certain criteria...
There's no such thing as 'individual class' because classes are defined in namespace and this namespace is located inside assembly and so on... Class has to be somewhere so it is always part of some bigger data structure.
Using of libraries also allows to re-use it in other projects and even solutions.
Let's illustrate it with two different scenarios :
Case 1 ->
You need to develop simple console app that needs to allow user to do some operation. So you define class Program with entry point (static void Main
) and class MyClass
that contains method DoOperation
, You also add some logic to your project and it is almost all that you need to do.
Case 2 ->
You need to develop software package that has many projects and most of them will use the same objects. That's when it's strongly recommended to create and use Class Library
project, define MyClass
and DoOperation
method there and make them public
and add link for this library to all these projects.

- 13,506
- 4
- 25
- 52