✅ 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?

17 Replies
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.
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 ?
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
yeah, we compile the class library into dll which can be re-used if needed?
correct
or well, not sure what you mean by "re-used"
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
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
ah I see
No idea what you are asking here
Like I mean, we create a class "Calculator"; I want to use this class later on in another project
when you compile a class library, the compiler runs just as it would with an executable. It makes IL code
to do so, I need to compile the "Calculator" class into a dll file ?
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.
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 ?
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 libyeahh I see
make more sense now
Thanks !!!
$close
If you have no further questions, please use /close to mark the forum thread as answered