简体   繁体   中英

c#: why use DLLs?

i'm working on a large c# project,i wonder why people use DLLs in their apps. I know that a dll file ( please correct if i'm wrong) contains some functions, but why don't we put those functions inside our main c# app?

Thanks

Most of it is summed up in the answer to this question , but the basic reasoning is "so you don't have to duplicate code".

Code reuse. Usually dll files contain functions that are useful in more than one app, and to have them in a single compiled file is a lot easier than copying over all that code.

Portability, Reusability, Modularity.

Splitting types and the like into separate assemblies allows you to reuse those types in different projects, maintain those types a modular fashion (eg update just one assembly instead of the whole app), and share parts of your code with others.

It also allows you to group common functionality into a single package.

Maintainability. When you need to fix a bug, you can release just the DLL containing the fix, instead of having to re-release the entire application.

This is an interesting question in a modern computing.

Back in the 16bit days DLLs cut down on the amount code in memory. This was a big issue when 16 meg computers where considered fully loaded.

I find many of the answers interesting as though a DLL is the only way to have a reusable,maintainable and portable library.

Good reasons for dll's are that you want to share code with an external party. Just as Visual Studio and other library vendors give you dll's this makes there code available to a external consumer. However, at one time they did distribute them in another way.

Patchable, This is true but how often does this really happen. Every company I've worked for has tested products as a unit. I suppose if you need to do incremental patching because of bandwidth or something this would be a reason.

As for all the other reasons including reusable, maintainable, modularity. I guess most of you don't remember.LIB files which were statically linked libraries. You can even distribute.LIB files but they have to be introduced at compile time and not runtime. They can help facilitate reusable, maintainable and modularity just like a DLL. The big difference is that they are linked when the program is compiled not when it is executed.

I'm really beginning to wonder if we shouldn't return to.LIB files for many things and reducing the number of DLL files. Memory is plentiful and there is overhead in load time when you have to load and runtime link a bunch of DLL files.

Sadly, .LIB files are only an option if your a C++ guy. Maybe they will consider them with C# in the future. I"m just not sure the reasons for DLL's still exist in the broad context they are used for today.

In big softwares, you have many teams they work on several different modules of program, and thay can proceed their goals without needing to know what others is doing, So one of the best solutions. is that each team produces own codes in parallel, So.dll comes to scene....

dll: a dynamic link library: it is a library. It contain some functions and data. Where we use these function? we use these function and data which are inside the dll,in another application or program. the most important thing is that dll will not get loaded into memory, when it require, called it is loaded into ram.

One of the best use is, one can integrate many third party functionalities into your application just by referencing the dlls, no need to use every third party tool/application into your system. For example, you need to send a meeting invite via MS outlook through code, for this simply refer the dlls provided by MS outlook in your application and you can start coding your way to success!

Extensibility - a lot of plugin frameworks use DLLs/Assemblies for plugins.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM