IBM to offer mobile security as a service IBM will start delivering mobile security-as-a-service (MaaS) through its own cloud infrastructure in India, a move that is expected to better address in-country data requirements... IBM Spectrum Computing: IBM has enlarged its portfolio of software-defined infrastructure solutions with cognitive features for workload management.  * LiFi internet technology has been introduced, the new type of wireless internet connection that gives 100 times faster than traditional WiFi -- Invented by Professor Harald Haas from the University of Edinburgh. * Sci. Rachid Yazami has developed a smart chip that charges smartphones in less than 10 minutes. BenQ has launched BlueCore projector - Consumer electronics major BenQ has launched its first BlueCore laser light source projector. For those unaware, devices with BlueCore laser technology have a high contrast output of 80000:1 with an extended lamp life and efficiency. *** 
  Jan 3 2015 10:38PM     Mohammad Shaik
  0 Comments    1612 Views  
Here Mohammad Shaik provided a short tutorial with example, about PreProcessor Directives in C#.
Preprocessor Directives
  1. The preprocessors directives give instruction to the compiler to preprocess the information before actual compilation starts.
  2. All preprocessor directives begin with #, and only white-space characters may appear before a preprocessor directive on a line. Preprocessor directives are not statements, so they do not end with a semicolon (;).
  3. C# compiler does not have a separate preprocessor; however, the directives are processed as if there was one. In C# the preprocessor directives are used to help in conditional compilation.
  4. C++ directives, they are not used to create macros. A preprocessor directive must be the only instruction on a line.
List of Preprocessor Directives in C#
The following table lists the preprocessor directives available in C#:
Preprocessor DirectiveDescription.
#defineIt defines a sequence of characters, called symbol.
#undefIt allows you to undefine a symbol.
#ifIt allows testing a symbol or symbols to see if they evaluate to true.
#elseIt allows to create a compound conditional directive, along with #if.
#elifIt allows creating a compound conditional directive.
#endifSpecifies the end of a conditional directive.
#lineIt lets you modify the compiler's line number and (optionally) the file name output for errors and warnings.
#errorIt allows generating an error from a specific location in your code.
#warningIt allows generating a level one warning from a specific location in your code.
#regionIt lets you specify a block of code that you can expand or collapse when using the outlining feature of the Visual Studio Code Editor.
#endregionIt marks the end of a #region block.
The #define Preprocessor
The #define preprocessor directive creates symbolic constants.
#define lets you define a symbol, such that, by using the symbol as the expression passed to the #if directive, the expression will evaluate to true. Its syntax is as follows:

#define symbol

The following program illustrates this:

#define PI 
using System;
namespace PreprocessorDAppl
   class Program
      static void Main(string[] args)
         #if (PI)
            Console.WriteLine("PI is defined");
            Console.WriteLine("PI is not defined");

When the above code is compiled and executed, it produces the following result:

PI is defined

Conditional Directives
You can use the #if directive to create a conditional directive.
Conditional directives are useful for testing a symbol or symbols to see if they evaluate to true. If they do evaluate to true, the compiler evaluates all the code between the #if and the next directive.
Syntax for conditional directive is:

#if symbol [operator symbol]...

Where, symbol is the name of the symbol you want to test. You can also use true and false or prepend the symbol with the negation operator.
The operator symbol is the operator used for evaluating the symbol. Operators could be either of the following:
  • == (equality)
  • != (inequality)
  • && (and)
  • || (or)
You can also group symbols and operators with parentheses. Conditional directives are used for compiling code for a debug build or when compiling for a specific configuration. A conditional directive beginning with a #if directive must explicitly be terminated with a #endif directive.
The following program demonstrates use of conditional directives:

#define DEBUG
#define VC_V10
using System;
public class TestClass
   public static void Main()

      #if (DEBUG && !VC_V10)
         Console.WriteLine("DEBUG is defined");
      #elif (!DEBUG && VC_V10)
         Console.WriteLine("VC_V10 is defined");
      #elif (DEBUG && VC_V10)
         Console.WriteLine("DEBUG and VC_V10 are defined");
         Console.WriteLine("DEBUG and VC_V10 are not defined");

When the above code is compiled and executed, it produces the following result:

DEBUG and VC_V10 are defined

I hope this page will helps to learn Operators in C#. Thanks.

Recent Posts
Create Amazon ElasticCache Using Memcached in CSharp
Nov 21 2017 12:09PM Posted By Amose
Get Google Map Lat Lng (Geo Point) By Pincode in C#
Nov 8 2017 10:26AM Posted By Pranav
Google URL Shortener in C#
Oct 26 2017 10:43AM Posted By Sanjay
Bind Gridview from CSV file in Asp.Net C#
Jun 18 2017 11:38PM Posted By Michael
Call WebService method from jQuery in every 1 minute
Feb 27 2017 11:51AM Posted By John
Gridview custom CSS in ASP.Net
Feb 25 2017 10:59AM Posted By Micheal Ryan
Read excel file and bind to Gridview in C#
Feb 25 2017 10:20AM Posted By Micheal
Follow us on Facebook
Follow us on Google +
Recent post in your Email inbox.
Enter your email address: