C # preprocessing commands

Source: Internet
Author: User

Preprocessing commands in C #
As a pair in Preprocessing: # Region name, # endregionIt may be the most widely used by everyone.CodeIn a long CS file, this is indeed a good way to make the code clearer. vs also uses this to automatically include the automatically generated code, by doing so, developers can view their code more clearly and enable a good header for more people to use # region.
C # contains several pairs of preprocessing commands, which may be rarely used.
# Define symbol
# UNDEF symbol
# If symbol [operator symbol2]...
# Else
# Elif symbol [operator symbol2]
# Endif
# Warning text refers to the warning text in the compiler output
# Error text indicates the error message in the compiler output.
# Line number

# Define debugging is equivalent to not writing this sentence. to define it, you must write # undefin debug
(In C # essentials, # define debug is equivalent to # define debug true, but thisIt seemsProblem)

This code can illustrate several commands:
# Define debug
# Define vc_v6
Using system;
Public class myclass
{
Public static void main ()
{

# If (debug &&! Vc_v6)
Console. writeline ("Debug is defined ");
# Elif (! Debug & vc_v6)
Console. writeline ("vc_v6 is defined ");
# Elif (debug & vc_v6)
Console. writeline ("Debug and vc_v6 are defined ");
# Else
Console. writeline ("Debug and vc_v6 are not defined ");
# Endif
}
}
We can use these commands to automatically handle tasks such as the connection strings of the database during the test period and the standby period.
# If! Release
Constr = testsqlserverconnectionstring
# Else
Constr = releasesqlserverconnectionstring
# Endif
Add # UNDEF resease to the Code, and delete this sentence after the code is published.

# Define debug

Using system;

Namespace syntaxtest
{
Public class class2
{
Public class2 ()
{
# If debug
# Warning debug is defined
# Endif
}
}
}
The above code generates a warning during compilation.

# Define debug

Using system;

Namespace syntaxtest
{
Public class class2
{
Public class2 ()
{
# If debug
# Error debug is defined
# Endif
}
}
}
The above code will generate an error during compilation and compilation fails. Therefore, we can use the above two commands to perform custom compilation detection.

# Line enables you to modify the compiler's row number and (optional) Output of file names for errors and warnings.

# Line [number ["file_name"] | default]

Number
ToSource codeThe number specified by the row following the object.
"File_name" (optional)
Name of the file to appear in the compiler output. By default, the actual name of the source code file is used. The file name must be enclosed in double quotation marks.
Default
Resets the row numbers in the file.
Remarks
# Line may be used by automatic intermediate steps during generation. For example, if the intermediate step removes rows from the original source code file, but you still want the compiler to generate output based on the original line number in the file, you can remove the row and use # line to simulate the original line number.

Public class myclass2
{
Public static void main ()
{
# Line 200
Int I; // This row contains 200 rows,But what we see in vs is 6.
# Line default
Char C; // This row is in 7 rows,But what we see in vs is 8.
}
}

From http://www.cnblogs.com/thinhunan/archive/2005/04/18/139518.html
Please criticize and correct.

Preprocessing commands in C #
As a pair in Preprocessing: # Region name, # endregionIt may be the most widely used, and I also use it to block code. In a long CS file, this is indeed a good way to make the code clearer. vs also uses this to automatically include the automatically generated code, by doing so, developers can view their code more clearly and enable a good header for more people to use # region.
C # contains several pairs of preprocessing commands, which may be rarely used.
# Define symbol
# UNDEF symbol
# If symbol [operator symbol2]...
# Else
# Elif symbol [operator symbol2]
# Endif
# Warning text refers to the warning text in the compiler output
# Error text indicates the error message in the compiler output.
# Line number

# Define debugging is equivalent to not writing this sentence. to define it, you must write # undefin debug
(In C # essentials, # define debug is equivalent to # define debug true, but thisIt seemsProblem)

This code can illustrate several commands:
# Define debug
# Define vc_v6
Using system;
Public class myclass
{
Public static void main ()
{

# If (debug &&! Vc_v6)
Console. writeline ("Debug is defined ");
# Elif (! Debug & vc_v6)
Console. writeline ("vc_v6 is defined ");
# Elif (debug & vc_v6)
Console. writeline ("Debug and vc_v6 are defined ");
# Else
Console. writeline ("Debug and vc_v6 are not defined ");
# Endif
}
}
We can use these commands to automatically handle tasks such as the connection strings of the database during the test period and the standby period.
# If! Release
Constr = testsqlserverconnectionstring
# Else
Constr = releasesqlserverconnectionstring
# Endif
Add # UNDEF resease to the Code, and delete this sentence after the code is published.

# Define debug

Using system;

Namespace syntaxtest
{
Public class class2
{
Public class2 ()
{
# If debug
# Warning debug is defined
# Endif
}
}
}
The above code generates a warning during compilation.

# Define debug

Using system;

Namespace syntaxtest
{
Public class class2
{
Public class2 ()
{
# If debug
# Error debug is defined
# Endif
}
}
}
The above code will generate an error during compilation and compilation fails. Therefore, we can use the above two commands to perform custom compilation detection.

# Line enables you to modify the compiler's row number and (optional) Output of file names for errors and warnings.

# Line [number ["file_name"] | default]

Number
The number specified for the row following the source code file.
"File_name" (optional)
Name of the file to appear in the compiler output. By default, the actual name of the source code file is used. The file name must be enclosed in double quotation marks.
Default
Resets the row numbers in the file.
Remarks
# Line may be used by automatic intermediate steps during generation. For example, if the intermediate step removes rows from the original source code file, but you still want the compiler to generate output based on the original line number in the file, you can remove the row and use # line to simulate the original line number.

Public class myclass2
{
Public static void main ()
{
# Line 200
Int I; // This row contains 200 rows,But what we see in vs is 6.
# Line default
Char C; // This row is in 7 rows,But what we see in vs is 8.
}
}

From http://www.cnblogs.com/thinhunan/archive/2005/04/18/139518.html
Please criticize and correct.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.