Most Viewed

Most Viewed

Sunday 15 July 2012

Conditional and Obsolete keyword in C#.Net

Conditional and Obsolete keyword in C#.Net

The attribute Obsolete is used to mark types and members of types that should no longer be used.

The Conditional attribute is an alias for ConditionalAttribute, and can be applied to a method or an attribute class



Demonstrate Conditional and Obsolete keyword in C#.Net
#define DEBUG
using System;
using System.Diagnostics;
class Class1
{            [Conditional ("DEBUG") ]
public static void disp1()       {
       Console.WriteLine(" Trying out Conditional Attributes") ;
              }
[Obsolete("this function is outdated!",false)] //changing false to true will cause error
public static void disp2(){    
Console.WriteLine(" Trying out an Obsolete Attributes") ;
              }
              static void Main(string[] args)
              {     disp1();disp2();Console.Read();
              }
}

No comments:

Post a Comment