我收到编译错误,因为编译器认为 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/