Hi Folks,
Today I am covering #pragma warning one of the preprocessor directives in C# 2.0.
C# language has many preprocessor directives like #if,#else,#endif similarly #pragma warning is one type of preprocessor directive .these directives are used to aid in conditional compilation. Unlike C and C++ directives, you cannot use these directives to create macros and preprocessor directive must be the only instruction on a line.
The #Pragma warning directive is used to enable or restore all or certain warning message during compilation .The syntax is
#pragma warning disable warning-list (disable directive disables the specified set of warnings)
#pragma warning restore warning-list (restore directives restore the specified set of warnings)
if you disable warning externally ( I mean by setting /nowarn option) # pragma restore will not enable the warning .
for example disable and restore the CLSCompliant attribute (cs3021)
// pragma_warning.cs
using System;
#pragma warning disable 3021
[CLSCompliant(false)]
public class MyClass
{
int i = 1;
public static void Main() // write your code here
{
}
}
#pragma warning restore 3021
[CLSCompliant(false)]
public class MyClass
{
int i = 1;
public static void Main() // write your code here
{
}
}
Cheeers
Anand
http://spaces.msn.com/members/anandkumar