1.使用别名

在同时引用的两个命名空间中有相同的类型时,可以使用别名来区分。如下所示:

using System;

using System.Threading;

using System.Timers;

其中在第二个和第三个引入的命名空间中有相同的Timer名字,这样可以使用using CountDownTimer=System.Timers.Timer;来为其中一个起一个别名来避免重名。也可以将别名设定为Timer。

using Timer=System.Timers.Timer;

class HelloWorld

{static void Main()

          { Timer timer;}}

现在使用Timer便没有歧义,如果再引用System.Threading.Timer类需要完全限定或者定义不同的别名。

相关文章:

  • 2022-12-23
  • 2022-01-28
  • 2021-05-31
  • 2022-03-05
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-09-05
  • 2022-12-23
  • 2021-11-11
  • 2022-12-23
  • 2021-07-16
  • 2022-01-19
相关资源
相似解决方案