
If a method has obsolete attributes, the compiler will issue a warning in the code after compilation.
When a new method is used in the class and you still want to keep the old method in the class, you can mark it as obsolete by showing a message that the new method should be used instead of the old method.
The following is an example showing how to use deprecated properties - p>
using System;
public class Demo {
[Obsolete("Old Method shouldn't be used! Use New Method instead", true)]
static void OldMethod() {
Console.WriteLine("This is the old method!");
}
static void NewMethod() {
Console.WriteLine("This is the new method!");
}
public static void Main() {
OldMethod();
}
}Since we set the warning message above, the following warning is displayed -
Compilation failed: 1 error(s), 0 warnings error CS0619: `Demo.OldMethod()' is obsolete: `Old Method shouldn't be used! Use New Method instead'
The above is the detailed content of Which properties are obsolete in C#?. For more information, please follow other related articles on the PHP Chinese website!