The shortest way is by adding the ObsoleteAttribute
as an attribute to the method .
(最简单的方法是将ObsoleteAttribute
作为方法的属性添加。)
Make sure to include an appropriate explanation: (确保包括适当的解释:)
[Obsolete("Method1 is deprecated, please use Method2 instead.")]
public void Method1()
{ … }
You can also cause the compilation to fail, treating the usage of the method as an error instead of warning , if the method is called from somewhere in code like this:
(如果从下面的代码中调用该方法,您也可能导致编译失败,将方法的使用视为错误而不是警告 。)
[Obsolete("Method1 is deprecated, please use Method2 instead.", true)]
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…