❔ how is c# project compiled??
Hello everyone, how is c# project compiled when it has several files, like 2 c# console applications?
14 Replies
One project can have multiply files in it...
But two console applications should be two different projects
When compiling project, Roslyn (C# compiler) just compiles all
.cs
files in this projectat the same time?
sooo, it just takes everything, connects into 1
.cs
file, runs, which means that I am not running file -> but instead running project??Yes, that's correct
in order to access that other class, it has to be public?
All classes in your project will be compiled; public is only about where in the code you can use the class
by the way what is it called when several c# projects are connected?
like here
In the screenshot you show only one c# project?
yes
What do you mean with several c# projects connected
2 C# files under 1 project
so that i could use classes/methods from other class in the main class
That's just a normal project? It's very rare to only have a single file in a project
C# projects can have thousands of files in them
You can use code from other files just like that
Nothing special needs to be done
I think you may have a bit of a misconception on what the word project means in C#. Unlike in, say, js or python, a single C# file is not a project. A project is the csproj file, and all of the cs files it says to include (all the cs files in the current directory and nested directories, by default)
When compiled, the cs files aren't combined into a single cs file and run. They are compiled to a lower-level language, cil (commom instruction language) and the instructions are put into a dll. Then that dll is run
When the dotnet runtime runs that dll, it takes the cil and jits (just-in-time compile) it to native machine code. No interpretation of your code happens, as in js or python
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.