When is the right time to use the C # class library (.dll)?

I am a programmer who has never used .dll files. The reason I need third-party software such as a graphics library, a library that helps me create graphics, etc. I add / ddl link files to my program and use them in my code.

Also, it looks like you can use .dll for many different things, so I would like the theme to focus on C #.

Now I am working on a disinfecting library (?) (I think this is the right term), which will be filled with appropriate methods that can sanitize variables in various ways.

I want to know:

will there be any advantage:

1) Write the methods to the class library → compile / create it → add the library as a reference to the program - what will need to sanitize some variables?

Or it will be exactly the same if I where:

2) Create a new SanitizeClass in the program → add all sanitation methods → call methods from SanitizeClass in different classes of the program that should sanitize the variables

In general, I also want to know when it is an advantage to using compiled class libraries. I think about speed, safety, all of this.

Can someone enlighten me? :)

+7
c # class dll class-library
source share
7 answers

Key question: does it make sense to use more than one application to use this type? If so, it should be in the class library. If not, you can put it in a class library just for the sake of separation (for example, have one assembly per level in an n-level solution), but you can just put it in your application.

If your disinfection is universal, then placing it in a class library will certainly be correct.

I know people who practically do not write code in executable applications, and put almost everything in class libraries, so the application basically just wraps class libraries. I am not inclined to go so far ...

+16
source share

The first thought that comes to mind is usability. Will this sanitation library ever be used outside the application you are currently working on? If so, then you do not want to have a link to exe in the future, for this you want to create a DLL file (maybe even a strong name and GAC), and then just link to it in the future.

+2
source share

Additional builds will add a little boot time and memory overhead, but otherwise will not have any performance impact.

Security will only matter if you need another code access protection (CAS) and use CAS.

Typically, there are three reasons:

  • This makes work easier. Putting just one assembly becomes cumbersome (this may include organizational / team issues).

  • Reuse.

  • You need separate assemblies. For example. have interfaces and implementations in different assemblies to allow AppDomains to be unloaded (for example, for plugins).

+2
source share

Using libraries is useful when you want to use code between several programs.

If you think you need your classes to sanitize data in more than one program, it is a good idea to put them in a library.

It is also recommended to place your application layers in different libraries (check the n-level architecture)

+1
source share

I think the easiest way is to add the SanitizeLibrary project as a library class project to your solution and specify this project in your application. If you find this useful, you can extract the library from the current project and refer to it as a dll in other projects.

0
source share

if you will reuse this code in different applications - that is: it will be some kind of shared library - then compile it as a dll

reg, note that any code that runs against an external compilation will always be slightly slower than executing code inside the same assembly

0
source share

What is the lib class?

We can create class files in all .NET applications (C # .Net, Asp.net, Asp.net MVC)

In Java, it is called a package! ...

In .Net we call it DLL (Dynamic Link Library)

If you create classes in your application, you can use these classes only inside this application, you cannot use it in other applications.

If you are creating a class library, you can use it in all applications.

When do you need to create and use Class Lib?

When we write the same code in another application, at that time we can create a class library and use it in all applications.

Example:

If you have the option to export excel in multiple applications, you can write the export code in the class library, and you can use it in several applications.

Real-time example:

A classroom is like a trash can in a room, and only room members can access it.

The lib class is like a trash can in a common place (college, train station), any of them can access and use it.

-one
source share

All Articles