×

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# - #pragma Preprocessor Directive Example

Learn about the #pragma preprocessor directive example in C# with the help of example.
Submitted by Nidhi, on October 31, 2020 [Last updated : March 23, 2023]

Here, we will demonstrate the example of #pragma preprocessor directive. We can enable or disable warnings using the #pragma directive. We can disable warning using #pragma disable and warning can be enabled using the #pragma restore directive.

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

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

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

using System;

class Program
{
   public static void Main()
    {
        #pragma warning restore
        #warning First warning
        #pragma warning disable
        #warning Second warning
    }
}

Output

Warning	1	#warning: 'First warning'

Explanation

The above program will generate a warning because we can enable or disable warnings using the #pragma directive. We can disable warning using "#pragma disable" and warning can be enabled using the "#pragma restore" directive.

Here, we created a Program class that contains the Main() method. The Main() method is the entry point for the program, here we used the #pragma directive to disable and enable warnings.

C# Basic Programs »

Advertisement
Advertisement

Comments and Discussions!

Load comments ↻


Advertisement
Advertisement
Advertisement

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