O'Reilly logo

From Java to C#: A Developer's Guide by Heng Ngee Mok

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

24.4. #warning and #error

The directives #warning and #error are used to make the compiler display a compiler warning or error message. For warnings, the compiler displays the warning message and then carries on with the compilation. Compilation warnings do not cause compilation to terminate. On the other hand, with errors the compiler displays an error message and terminates the compilation process. Here is an example:

 1: using System;
 2:
 3: public class TestClass{
 4:
 5:   public static void Main(){
 6: #warning Main not yet completed
 7:     Console.WriteLine("to be done");
 8:     // insert code here after New Year holidays
 9:     //...
10:   }
11: }

Compilation warning:

test.cs(6,11): warning CS1030: #warning: 'Main not yet
completed'

Output:

 c:\expt>test ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required