Ron*_*rby 13 c# using using-directives
我在代码示例中看到了这个C#using语句:
using StringFormat=System.Drawing.StringFormat;
Run Code Online (Sandbox Code Playgroud)
那是什么意思?
mbi*_*ard 13
它是别名,从现在开始,用户可以使用StringFormat来引用System.Drawing.StringFormat.如果您不想使用整个命名空间(例如,在名称冲突问题的情况下),这将非常有用.
来源:使用MSDN的指令文章
也许在另一个名称空间(如Acme.Stuff)中声明了一个不同的,无关的StringFormat.如果是这种情况,这会引起混淆:
using System.Drawing; // Contains StringFormat type.
using Acme.Stuff; // Contains another StringFormat type.
private void Foo()
{
StringFormat myFormat = new StringFormat(); // which one to use?
}
Run Code Online (Sandbox Code Playgroud)
别名是在StringFormat = System.Drawing.StringFormat上使用,清除了一些混乱.
| 归档时间: |
|
| 查看次数: |
9504 次 |
| 最近记录: |