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類需要完全限定或者定義不同的別名。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM