c# - 在命名空间中使用与我现在工作同名的方法

标签 c# namespaces

它很奇怪....

有一个名为 的命名空间Android.Graphics 我在名为 的命名空间中工作Xamarin.FormsBook.Platform.Android .

还有一个名为 的命名空间Xamarin.Forms 它有颜色字段。

现在,我想使用 Android.Graphics.Color 所以我写颜色然后一些东西识别它为 Xamarin.Forms.Color 不是 Android.Graphics.Color .

enter image description here

而且,如果我写 Android.Graphics.Color 构建器找不到 Android.Graphics。如果我写安卓。然后构建器找到 Xamarin.FormsBook.Platform.Android 的方法和字段。

enter image description here

如果我写 Android.Graphics.Color 在命名空间区域之外,然后它识别。

enter image description here

但是我无法在其中分配任何值,因为“命名空间不能直接包含成员,例如字段或方法”。

帮帮我,我想使用 Android.Graphic 的颜色

最佳答案

您可以使用 alias directive 来做到这一点。 :

using AndroidGraphics = Android.Graphics;

然后您可以引用Android.Graphics.Color使用别名输入 AndroidGraphics.Color .因为没有另一个名为 AndroidGraphics 的命名空间您的编译器将正确解析它。

Alias 指令也可用于单个类型,因此您还可以执行以下操作:
using AndroidColor = Android.Graphics.Color;

然后使用 AndroidColor 引用类型.

关于c# - 在命名空间中使用与我现在工作同名的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40670268/

相关文章:

c# - 使用 WiX 工具集编辑文件

c# - 使用 LINQ Select 扩展方法后的项目顺序

language-agnostic - 如何避免类名和命名空间冲突?

asp.net-mvc - 如何在 Visual Studio 2015 中快速解析命名空间

c# - View 中的 MVVM 访问模型

c# - 将重复键添加到 NameValueCollection

c# - Context.SaveChanges() 挂起,似乎是由于 Entity Framework 中的嵌套事务和 FK 约束

javascript - 如何在不覆盖另一个同名对象的情况下创建一个空的命名空间对象?

PHP 命名空间和包含

c# - 阻止 VS 自动添加 using 指令