Ylbtech-languagesamples-conditionalmethods (Conditional method)

Source: Internet
Author: User

Ylbtech-microsoft-csharpsamples:ylbtech-languagesamples-conditionalmethods (Conditional method)

1.A, example (sample) back to top
Conditional Methods Sample

This example demonstrates conditional methods, which provide a powerful mechanism through which method calls can be included or omitted depending on whether a symbol is defined.

Safety Instructions

This code example is provided to illustrate a concept that does not represent the most secure coding practice, so you should not use this code example in an application or Web site. Microsoft assumes no responsibility for incidental or consequential damages arising from the use of this code sample for other purposes.

To build and run the conditional methods sample in Visual Studio
    1. In Solution Explorer, right-click the project and then select Properties.

    2. Open the Configuration Properties folder and click Debug.

    3. Set the command line Arguments property to "A B C" (without the quotation marks).

    4. In the Configuration Properties folder, click Build.

    5. Modify the conditional compilation constants property (for example, add or remove DEBUG), and then click OK.

    6. On the Debug menu, click Start Without Debugging.

To build and run the conditional methods sample from the command line
    • To include a conditional method, type the following at a command prompt to compile and run the sample program:

      csc CondMethod.cs tracetest.cs/d:debugtracetest A B C
1.B, sample code back to top

1.b.1, CondMethod.cs

//Copyright (C) Microsoft Corporation. All rights reserved. //This code is published in compliance with//Microsoft Public License (MS-PL,http://opensource.org/licenses/ms-pl.html) of the terms. ////Copyright (C) Microsoft Corporation. All rights reserved. //CondMethod.cs//compile-time use:/target:library/d:debugusingSystem;usingSystem.Diagnostics;namespacetracefunctions { Public classTrace {[Conditional ("DEBUG")]         Public Static voidMessage (stringtracemessage) {Console.WriteLine ("[TRACE]-"+tracemessage); }    } }
View Code

1.b.2, Tracetest.cs [Main]

//Copyright (C) Microsoft Corporation. All rights reserved. //This code is published in compliance with//Microsoft Public License (MS-PL,http://opensource.org/licenses/ms-pl.html) of the terms. ////Copyright (C) Microsoft Corporation. All rights reserved. //TraceTest.cs//compile-time use:/reference:condmethod.dll//parameter: A B CusingSystem;usingtracefunctions; Public classtraceclient { Public Static voidMain (string[] args) {Trace.message ("Main Starting"); if(args. Length = =0) {Console.WriteLine ("No arguments have been passed"); }       Else       {            for(intI=0; I < args. Length; i++) {Console.WriteLine ("arg[{0}] is [{1}]", I,args[i]); }} trace.message ("Main Ending"); } }
View Code

1.b.3,

1.C, (free Download) back to top

Ylbtech
Source: http://ylbtech.cnblogs.com/
This article is copyright to the author and the blog Park, Welcome to reprint, but without the consent of the author must retain this paragraph, and in the article page obvious location to the original link, otherwise reserves the right to pursue legal responsibility.

Ylbtech-languagesamples-conditionalmethods (Conditional method)

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.