what are hashtags for in C#?

i've written C# for a month and have zero idea what these hashtag symbols are for. like #define - what does that do?
16 Replies
Pobiega
Pobiega5mo ago
its a preprocessor directive
ACiDCA7
ACiDCA75mo ago
Preprocessor directives - C# reference
Learn the different C# preprocessor directives that control conditional compilation, warnings, nullable analysis, and more
sashimikitty
sashimikitty5mo ago
its basically a line that executes only when the scripts compiles, for example: #undef DEBUG (makes DEBUG tag to false) #if DEBUG all the code here doesnt get compiled, its like it never existed and wont show in the decompiled dll #endif
slowly losing it
slowly losing itOP5mo ago
so you can add extra properties based on maybe the OS the executable is run on?
sashimikitty
sashimikitty5mo ago
yep for example
sashimikitty
sashimikitty5mo ago
another example would be a game engine version or the version of an asset you downloaded
No description
Pobiega
Pobiega5mo ago
Not run on, compiled on. Preprocessor directives are only used during compilation
slowly losing it
slowly losing itOP5mo ago
when is a dotnet exe compiled then? if i run the final .exe, does any of the preprocessing directives get executed? or is that only when compiled? or i guess, to rephrase, does running an exe "recompile" it, in some way? or is this in the case of maybe a github repo where downloading the code and building the project yourself would invoke the PPDs
ACiDCA7
ACiDCA75mo ago
the code gets compiled when your sourcecode gets transformed into exe/dll
Pobiega
Pobiega5mo ago
not at all
slowly losing it
slowly losing itOP5mo ago
https://discord.com/channels/143867839282020352/1294321833587245097/1295449296585363487 so in the case of this, depending on where you build the project, you can have different changes for each different OS?
MODiX
MODiX5mo ago
it’s raining outside
or is this in the case of maybe a github repo where downloading the code and building the project yourself would invoke the PPDs
Quoted by
React with ❌ to remove this embed.
slowly losing it
slowly losing itOP5mo ago
oh damn, thats handy
Pobiega
Pobiega5mo ago
yes. they are not very common for a reason
sashimikitty
sashimikitty5mo ago
basically compiling = take c# and make it binary (very very basically)
slowly losing it
slowly losing itOP5mo ago
ah i see thank you, all of you i'll close this tomorrow morning

Did you find this page helpful?