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
Pobiega2mo ago
its a preprocessor directive
ACiDCA7
ACiDCA72mo ago
Preprocessor directives - C# reference
Learn the different C# preprocessor directives that control conditional compilation, warnings, nullable analysis, and more
sushiman
sushiman2mo 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
it’s raining outside
so you can add extra properties based on maybe the OS the executable is run on?
sushiman
sushiman2mo ago
yep for example
sushiman
sushiman2mo ago
another example would be a game engine version or the version of an asset you downloaded
No description
Pobiega
Pobiega2mo ago
Not run on, compiled on. Preprocessor directives are only used during compilation
it’s raining outside
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
ACiDCA72mo ago
the code gets compiled when your sourcecode gets transformed into exe/dll
Pobiega
Pobiega2mo ago
not at all
it’s raining outside
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
MODiX2mo 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.
it’s raining outside
oh damn, thats handy
Pobiega
Pobiega2mo ago
yes. they are not very common for a reason
sushiman
sushiman2mo ago
basically compiling = take c# and make it binary (very very basically)
it’s raining outside
ah i see thank you, all of you i'll close this tomorrow morning
Want results from more Discord servers?
Add your server