当前位置: 代码迷 >> C# >> c# using 摘引和别名的使用
  详细解决方案

c# using 摘引和别名的使用

热度:418   发布时间:2016-05-05 04:40:32.0
c# using 引用和别名的使用

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类需要完全限定或者定义不同的别名。

  相关解决方案