c# - 跳过为结构提供完整命名空间引用的最佳方法是什么?

标签 c# namespaces

我想声明一个颜色数组,用作 8 位样式 Sprite 。

spriteArray = new System.Drawing.Color[2,2] {
{System.Drawing.Color.Red, System.Drawing.Color.Blue},
 {System.Drawing.Color.Blue, System.Drawing.Color.Red}
};

这很痛苦,而且每次都写出命名空间路径看起来很冗长 - 最好的方法是将其简化为如下内容:

spriteArray = new System.Drawing.Color[2,2]
{{RED, BLUE},
 {BLUE, RED}};

是?

最佳答案

在代码文件的顶部包含一个 using 指令:

using System.Drawing;

那么就是:

spriteArray = new Color[2,2]
{
    { Color.Red, Color.Blue },
    { Color.Blue, Color.Red } 
};

关于c# - 跳过为结构提供完整命名空间引用的最佳方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23102104/

相关文章:

c# - Blazor EditForm 和 Fluent 验证

c# - 状态 cookie 无效。处理远程登录时遇到错误。 ASP.NET Core MVC 外部社交登录

c# - 当 .NET 不在垃圾回收 (GC) 中间时,如何捕获 .NET 进程的进程内存转储

WPF:ComboBox DisplayMemberPath 突然不再显示了?

ruby-on-rails - 如何使用与 gem 同名的模型?

python - inspect.getmembers() vs __dict__.items() vs dir()

grails - 在 Grails 模板命名空间中,如何使用另一个目录中的模板

c# - .NET:为什么嵌套类具有在外部类中声明的泛型?

c# - System.XML 或 Regex.Replace?

import - 对 TypeScript 模块感到困惑