System.ObsoleteAttribute

作者:追风剑情 发布于:2016-10-21 14:53 分类:C#

用来标识已过时的类或方法。

示例

  1. using System;
  2.  
  3. namespace TTest
  4. {
  5. class Program
  6. {
  7. static void Main(string[] args)
  8. {
  9. A a = new A();
  10. B b = new B();
  11. b.OldMethod();
  12. b.NewMethod();
  13. Console.Read();
  14. }
  15. }
  16.  
  17. [System.Obsolete("use class B")]
  18. class A
  19. {
  20. public void Method() { }
  21. }
  22. class B
  23. {
  24. [System.Obsolete("use NewMethod", true)]
  25. public void OldMethod() { }
  26. public void NewMethod() { }
  27. }
  28. }

 

编译截图

11111.png

 

标签: C#

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号