C#:属性/字段命名空间歧义

标签 c# properties namespaces syntax-error collision

我收到编译错误,因为编译器认为 Path.Combine 指的是我的字段,但我希望它指的是类 System.IO.Path。除了总是必须像 System.IO.Path.Combine() 那样编写 FQN 之外,是否有处理此问题的好方法?

using System.IO;

class Foo
{
   public string Path;

   void Bar(){ Path.Combine("",""); } // compile error here
}

最佳答案

你可以这样做:

using IOPath = System.IO.Path;

然后在你的代码中:

class Foo
{
   public string Path;

   void Bar(){ IOPath.Combine("",""); } // compile error here
}

关于C#:属性/字段命名空间歧义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1028489/

相关文章:

c# - WCF SSL 负载均衡器。负载均衡器更改 ssl 端口

C# 属性 - 需要子属性

security - Kubernetes - 动态命名空间/安全

c# - 无法使用 Properties.Settings 从 app.config 中读取

encoding - 使用 Jaxb 属性设置 XML 的编码

php - 命名空间适用于一个类,但不适用于其他类

c# - 如何使用 C# 包含来自不同文件夹的命名空间

c# - .Net Remoting 不使用.Net Remoting?

c# - json序列化格式化

c# - System.Drawing 对于我们想要做的事情来说太慢了吗?