1

我得到编译错误,因为编译器认为 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
}
4

2 回答 2

5

你可以这样做:

using IOPath = System.IO.Path;

然后在您的代码中:

class Foo
{
   public string Path;

   void Bar(){ IOPath.Combine("",""); } // compile error here
}
于 2009-06-22T17:37:18.907 回答
3

分开你的参考:

this.Path = System.IO.Path.PathFunction();

我强烈建议在该类中的任何位置使用 Path 时暗示 System.IO 命名空间,因为很难区分。使用这个。限定符和完整的命名空间使它们与众不同。

于 2009-06-22T17:42:59.400 回答