Sponsored Ad

Friday, October 23, 2009

#line & #pragma

C#line

The #line directive can be used to alter the file name and line number information that is output by the compiler in warnings and error messages. You probably won ’ t want to use this directive that often. It ’ s most useful when you're coding in conjunction with some other package that alters the code you're
typing in before sending it to the compiler. In this situation, line numbers, or perhaps the file namesreported by the compiler, won ’ t match up to the line numbers in the files or the file names you're editing. The #line directive can be used to restore the match. You can also use the syntax #line default to restore the line to the default line numbering:

#line 164 “Core.cs” // We happen to know this is line 164 in the file

// Core.cs, before the intermediate

// package mangles it.

// later on

#line default // restores default line numbering

#pragma

The # pragma can remove or restore specific compiler warnings. Unlike command - line options, the # pragma can be implemented in a class or method level, which allows a fine - grained control what and when warnings are suppressed. In the following example disables the "not used"  warning and then returned after class MyClass compile:

#pragma warning disable 169
public class MyClass
{
int neverUsedField;
}
#pragma warning restore 169

0 comments:

Post a Comment

Sponsored Ad

Website Update

Followers