Mega Code Archive

 
Categories / C# Tutorial / Attribute
 

Demonstrate the Obsolete attribute

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