我有一个C#程序,如下所示。但它失败了。 错误是由于其保护级别而无法访问“System.IO.FileSystemInfo.FullPath”。 而FullPath以蓝色下划线。“System.IO.FileSystemInfo.FullPath”由于其保护级别“C#中的错误而无法访问”
protected void Main(string[] args)
{
DirectoryInfo parent = new DirectoryInfo(@"C:\Users\dell\Desktop\rename");
foreach (DirectoryInfo child in parent.GetDirectories())
{
string newName = child.FullPath.Replace('_', '-');
if (newName != child.FullPath)
{
child.MoveTo(newName);
}
}
}
也许你打算ü se全名,而不是FullPath。 FullPath是一个受保护的字段,它不是以这种方式使用的。有关访问修饰符的说明,请参阅http://msdn.microsoft.com/en-us/library/ms173121.aspx。对于FileSystemInfo的字段/属性,请参考:http://msdn.microsoft.com/en-us/library/system.io.filesysteminfo.aspx – 2012-03-07 22:52:18
感谢您的帮助:)我将其更改为FullName,并将“公共静态“到”受保护“。它现在有效。我正在结束这个问题。再次感谢:) – cethint 2012-03-07 22:57:59
你总是可以看到该领域是否受到保护,私人等。按F12。 //总结: //为System.IO.FileInfo和System.IO.DirectoryInfo提供基类//对象。 [序列化] [标记有ComVisible特性(真)] 公共抽象类FileSystemInfo:MarshalByRefObject的,ISerializable的 { //摘要: //表示的目录或文件的完全合格的路径。 保护字符串FullPath; – 2012-03-07 22:59:16