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";
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
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.