C
C#3w ago
Faker

✅ What is a DLL (Dynamic Link Library) file? Why is it useful?

Hello guys, can someone explain what is a DLL file and why is it useful please. From what I've read, DLL are files that contain compiled code, that is the intermediate code that will be interpreted by the .NET runtime. But notice the call stack in the picture; they are all DLL file within the same main file, so I'm a bit confused, the compiler doesn't compile everything related to a single main file into another main compiled file?
No description
17 Replies
Pobiega
Pobiega3w ago
Generally, in C#, a single project => a single DLL file Your project appears to be a console app with a single class in a single project, thus there is only 1 dll file.
Faker
FakerOP3w ago
ah, we are referencing multiple methods within the same .dll file, my bad, I thought we were creating a dll file for each method of the file so basically, why do we need the dll file? so that is can be re-used if we wanted to later on ?
Pobiega
Pobiega3w ago
what else would a class library compile to? remember, class library is a valid stand-alone project type I can sort of understand the question in terms of "I'm making an app and I have 2 libraries, they are not useful on their own, only as part of my app - there should be a single executable file produced" (and there are publishing settings that would help here), but since class libs can be stand-alone, there needs to be something that they can compile to on their own
Faker
FakerOP3w ago
yeah, we compile the class library into dll which can be re-used if needed?
Pobiega
Pobiega3w ago
correct or well, not sure what you mean by "re-used"
Faker
FakerOP3w ago
when we say "we compile the class library", we just save a project with that class or their actually some compilation to be done to create the .dll file
Pobiega
Pobiega3w ago
you can copy a .NET dll and load it into a different project for example but each process woudl still load the DLL, even if they referred to the exact same file via symlink or whatever
Faker
FakerOP3w ago
ah I see
Pobiega
Pobiega3w ago
No idea what you are asking here
Faker
FakerOP3w ago
Like I mean, we create a class "Calculator"; I want to use this class later on in another project
Pobiega
Pobiega3w ago
when you compile a class library, the compiler runs just as it would with an executable. It makes IL code
Faker
FakerOP3w ago
to do so, I need to compile the "Calculator" class into a dll file ?
Pobiega
Pobiega3w ago
no not the class the class library that contain that class classes are not compiled to individual files in C#, unlike java a class library is a project. in C#, we compile projects.
Faker
FakerOP3w ago
ahhh ok I see yeah, that was the confusion I thought a class library is the same thing as a class but a class library is a collection of classes, the project itself as you said So, I have the calculator class, in order to use it else where, I need to compile the class library for that project; in order to compile it, how is that done, we just run the project ?
Pobiega
Pobiega3w ago
yep huh
in order to compile it, how is that done, we just run the project?
no you... compile it? with dotnet publish ideally you can't dotnet run a class lib
Faker
FakerOP3w ago
yeahh I see make more sense now Thanks !!! $close
MODiX
MODiX3w ago
If you have no further questions, please use /close to mark the forum thread as answered

Did you find this page helpful?