C# Pragma to disable unused constants

A somewhat dated style of coding, commonly seen in WinAPI code, creates a list of constants for use in called methods. Occasionally I find this concept handy and illustrative, such as when using 32-bit resources because the 64-bit equivalent is not yet suitable. However, you’ll get a compiler warning for any unused variables. The warning can be eliminated with a #pragma:

#pragma warning disable 0414 //disable the compilation warning "The field 'XYZ' is assigned but its value is never used".
    static readonly string CRYSTAL_REPORTS_EXE_x86_ON_64 = @"C:\Program Files (x86)\Business Objects\Common\2.8\bin\objectfactory.dll";
#pragma warning restore 0414 //enable the compilation warning "The field 'XYZ' is assigned but its value is never used".
    static readonly string CRYSTAL_REPORTS_EXE = @"C:\Program Files\Business Objects\Common\2.8\bin\objectfactory.dll";
Your date can also choose any movie they want, you are not just limited to buy cheapest cialis the selection on offer at the same medicine at a discounted price in online drug stores. Obesity is one of the major risk buy viagra in bulk aspects; obesity, neural diseases caused by diabetes, blood pressure imbalance, hormonal imbalance, and high cholesterol, are the most complicated, and also time consuming ones. It ensures harder and fuller erection for order generic viagra wouroud.com pleasurable lovemaking. To avoid the prescription, expensive and quick-fix drugs these natural ingredients are mixed using an advanced herbal formula and processed in the decoction of Gokhru, Musli Sya and Musli Safed. cialis 5 mg

Here’s an example of why the somewhat dated WIPAPI style of coding is still useful. You see all of the options can be explicitly listed, similarly to how an enum can list them. It is usually preferable to use an enum or object properties versus a loose collection of strings, but if you must pass a string into a method then a collection of strings can be more clear.

static readonly string MB_ICONQUESTION As Integer = &H20
static readonly string MB_YESNO As Integer = &H4
static readonly string IDYES As Integer = 6
static readonly string IDNO As Integer = 7

This entry was posted in C#, Programming. Bookmark the permalink.

One Response to C# Pragma to disable unused constants

  1. pfb_admin says:

    These related warning numbers have also been useful:
    #pragma warning disable 0168 // variable declared but not used.
    #pragma warning disable 0219 // variable assigned but not used.
    #pragma warning disable 0414 // private field assigned but not used.
    #pragma warning disable 0169 // The field ‘XYZ’ is never used.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.