C # Learning notes: Preprocessing directives

Source: Internet
Author: User

C # and C + +, as well as preprocessing directives, let's look at preprocessing directives in C #.

#region

Code folding function, with #endregion use, as follows:

Click below:

Conditional preprocessing

Conditional preprocessing can determine the final compiled code based on the conditions given, in other words, you can exclude the specified code from compiling.

#define

Define a macro, and note that if you define a name, you do not need a value.

The macro definition is generally written in the first line.

#define IOS

This means that the macro for iOS is defined.

#undef

Cancel a macro definition, as follows:

#undef IOS

This will cancel the macro definition of iOS.

#if, #else, #elif, #endif

For specific instructions, show examples below:

1 #define ANDROID 2 #define iOS 3 #undef iOS 4  5 using System; 6  7 namespace Study 8 {9     class PROGRAM10     { One         by one static void Main (string[] args)         {#if ANDROID15             Console.WriteLine ("The Code of the Android platform is written here. "); #elif IOS17             Console.WriteLine (" IOS platform code is written here. "); #else19             Console.WriteLine (" The Code for the other platforms is written here. "); #endif21             console.read ();         }24     }25}

In unity, the corresponding macros have been defined for the corresponding platforms and versions, and the following links can be viewed:

Http://docs.unity3d.com/Manual/PlatformDependentCompilation.html

#warning, #error

These two instructions allow the editor to make warnings and errors, with general and conditional directives for debugging.

1 #warning shouldn't write like this here! 2 #error It's wrong to write like this here!
#line

With #warning and #error, you can set the exact number of lines for an error or warning.

1//200 Line problem 2 #line 200 "optional file name, indicating the specific problem file, without the suffix name. "3//recovery rows are the current number of rows 4 #line default
#pragma

This instruction can be extended by ourselves to complete specific functions, here is not much to say, to everyone a link to the article:

http://blog.csdn.net/jx_kingwei/article/details/367312

C # Learning notes: Preprocessing directives

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.