Demonstrate the Obsolete attribute. : Obsolete Attribute « Attribute « C# / CSharp Tutorial






using System; 
 
class MainClass { 
 
  [Obsolete("Use myMeth2, instead.")]  
  static int myMethod(int a, int b) { 
    return 0; 
  } 
 
  // Improved version of myMethod. 
  static int myMethod2(int a, int b) { 
    return 1; 
  } 
 
  public static void Main() { 
   // warning displayed for this 
    Console.WriteLine("4 / 3 is " + myMethod(4, 3)); 
 
   // no warning here 
    Console.WriteLine("4 / 3 is " + myMethod2(4, 3));  
  } 
}
4 / 3 is 0
4 / 3 is 1








10.2.Obsolete Attribute
10.2.1.The Obsolete Attribute
10.2.2.Demonstrate the Obsolete attribute.
10.2.3.Obsolete attribute: warn the user that Method is obsolete
10.2.4.Obsolete attribute: throw an error if the user tries to use Method2
10.2.5.Using ObsoleteAttribute