我得到编译错误,因为编译器认为 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
}
我得到编译错误,因为编译器认为 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
}
分开你的参考:
this.Path = System.IO.Path.PathFunction();
我强烈建议在该类中的任何位置使用 Path 时暗示 System.IO 命名空间,因为很难区分。使用这个。限定符和完整的命名空间使它们与众不同。