1 [Conditional ( " Debug " )]
2 Private Void Debug_trace ( String Strmsg)
3 {
4Console. writeline (strmsg );
5}
this statement is clear. The Code is easy to read and can shield potential bugs. 1 debug_trace ( " error message1 " );
2 console. writeline ( " message " );
3 debug_trace ( " error message2 " );
For this codeReleaseGenerated inIlThe Code is the same as the following code.Console. writeline ("Message");
HoweverConditionalThe attribute function has a limit, that is, it cannot return values, that is, it must useVoidTo define the return value.
AndConditionalTo add multiple attributes, for example:
[Conditional ("debug"), conditional ("trace")]
Private VoidDebug_trace (StringStrmsg)
{
Console. writeline (strmsg );
}
However, the relationship between these two attributes is or, that is,"Debug"Or"Trace"If any one is defined, this code will be executed. If you need to add two parallel attributes, directly useConditionalIt cannot be implemented.If/endifAs follows:
# If(Debug & trace)
# DefineBoth
# Endif
[Conditional ("both")]
Private VoidDebug_trace (StringStrmsg)
{
Console. writeline (strmsg );
}
The method has already been mentioned here. It can be basically done. Next, let's talk about how to set environment variables inC #There are three setting methods.
Method 1:ProgramAnd must be defined at the beginning of a file;
Method 2: set it in the compilation command line of the project;
Method 3: Add environment variables to the operating system.