惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

WordPress大学
WordPress大学
T
Threatpost
阮一峰的网络日志
阮一峰的网络日志
美团技术团队
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
月光博客
月光博客
V
Visual Studio Blog
T
Tailwind CSS Blog
Stack Overflow Blog
Stack Overflow Blog
博客园 - 聂微东
Jina AI
Jina AI
J
Java Code Geeks
Martin Fowler
Martin Fowler
大猫的无限游戏
大猫的无限游戏
Recorded Future
Recorded Future
C
Check Point Blog
腾讯CDC
N
Netflix TechBlog - Medium
aimingoo的专栏
aimingoo的专栏
罗磊的独立博客
Hacker News: Ask HN
Hacker News: Ask HN
SecWiki News
SecWiki News
博客园 - Franky
Hacker News - Newest:
Hacker News - Newest: "LLM"
N
News | PayPal Newsroom
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
S
Security @ Cisco Blogs
W
WeLiveSecurity
The Last Watchdog
The Last Watchdog
Cloudbric
Cloudbric
F
Full Disclosure
The Cloudflare Blog
Y
Y Combinator Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Google DeepMind News
Google DeepMind News
MongoDB | Blog
MongoDB | Blog
S
Schneier on Security
Schneier on Security
Schneier on Security
Spread Privacy
Spread Privacy
L
LINUX DO - 热门话题
AI
AI
N
News and Events Feed by Topic
T
Tor Project blog
P
Palo Alto Networks Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
Google Developers Blog

博客园 - 真见

用户中心 - 博客园 如何在ASP.NET中使用Windows Live Web Bar 博客园的一篇好文 Internet Explorer 8.0 正式版 提交按钮OnCheck之后的技巧 - 真见 - 博客园 如何在ASP.NET中使用Syndication创建一个RSS源 如何创建Sql Server数据库关系图 + Silverlight 2 GDR1 发布 ASP.NET WebForms 4.0 新属性 如何在ASP.NET中使用验证通过的Windows Live ID用户登录网站 我的Windows 7系统 Internet Explorer 8 RC1发布 新浪首届我的创业路征文大赛初评榜单公布 得到微软DevWow博客达人征文大赛优秀奖,奖得微软T-Shirt一件 我的五项 Windows Live Writer 使用习惯分享 + 来自 Jackson Fish Market 的虚拟鲜花赠送服务推荐 摇滚真见的生日 Sueetie源代码发布【 推荐 】 中国版 Windows Live Wave3 介绍站点 ASP.NET网站编程人员2008年技术文章参照 Visual Studio可视化IDE风格主题参照
Using-更精彩更有用的做法-短签名
真见 · 2009-02-03 · via 博客园 - 真见

一般我们编程的时候Using默认一般做法如下:

 using System;  
 using System.Collections.Generic;  
 using System.Text.RegularExpressions;  
 using System.Net;  
 using System.IO; 

但是,有很多情况,比如,现在有2个类,类名都叫Class1,2个类在不同的名称空间,现在要在同一文件中提取这2个类,你一般做法是:

namespace  SampleClass{
     class TestClass{
         private void F(){
              Namespace.one.Class1 c1= new Namespace.one.Class1();
              Namespace.two.Class1 c2= new Namespace.two.Class1();
         }
    }
}
或者
using Namespace.one;

namespace  SampleClass{
     class TestClass{
         private void F(){
              Class1 c1= new Class1();
              Namespace.two.Class1 c2= new Namespace.two.Class1();
         }
    }
}
 

现在,有一种解决方法避免这种情况,当然也不算避免,但是可以使用更短的名字:有2中方法,第一种叫别名称,

using Namespace.one;
using T = Namespace.two;

namespace  SampleClass{
     class TestClass{
         private void F(){
              Class1 c1= new Class1();
              T.Class1 c2= new T.Class1();
         }
    }
}

第二种方法叫 别类名:

using Namespace.one;
using T = Namespace.two.Class1;

namespace  SampleClass{
     class TestClass{
         private void F(){
              Class1 c1= new Class1();
              T c2= new T();
         }
    }
}

怎么样,Class1和T那个更短,这让我想起来了现在流行的短URL服务网站兴起的重要。。