×

C# Tutorial

Basics of .Net

C# Basics

C# Fundamentals

C# Operators

C# Loops

C# Type Conversions

C# Exception Handling

C# String Class

C# Arrays

C# List

C# Stack

C# Queue

C# Collections

C# Character Class

C# Class and Object

C# Namespaces

C# Delegates

C# Constructors

C# Inheritance

C# Operator Overloading

C# Structures

C# File Handling

C# Convert.ToInt32()

C# Int32 (int) Struct

C# DateTime Class

C# Uri Class

C# Database Connectivity

C# Windows

C# Other Topics

C# Q & A

C# Programs

C# Find O/P

C# - #warning Preprocessor Directive Example

Here, we will use the #warning directive then the program will generate a warning with a specified message after the compilation of the program.
Submitted by Nidhi, on October 31, 2020 [Last updated : March 23, 2023]

Here, we will use the #warning directive then the program will generate a warning with a specified message after the compilation of the program.

C# program to demonstrate the example of #warning preprocessor directive

The source code to demonstrate the #warning preprocessor directive is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to demonstrate the 
//#warning preprocessor directive.

#define MACRO1
#define MACRO2
#define MACRO3
#undef  MACRO2

using System;

class Program
{
   public static void Main()
   {
        #if (!MACRO2)
            #warning MACRO2 is not defined
        #endif
    }
}

Output

Warning	1	#warning: 'MACRO2 is not defined'

Explanation

The above program will generate a warning because here we used the #warning directive with a specified message in the Main() method then the specified message will print as a warning when we compile the program.

C# Basic Programs »

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

Copyright © 2025 www.includehelp.com. All rights reserved.