c#的错误

来源:百度知道 编辑:UC知道 时间:2024/05/18 07:08:34
帮忙看下哪错了?
谢谢

using System;
using System.IO;

namespace text001
{
class Program
{
public static void Main()
{
Directory d = new Directory("e:\\c###");
Directory d1;
Directory d2;
try
{
d1 = d.CreateSubdirectory("file1");
}
catch (IOException e)
{
Console.WriteLine("directory file1 failed because: {0}", e);
return;
}
try
{
d2 = d.CreateSubdirectories("file1\\file2");
//等于d2 = d1.CreateSubDirectory("file2");
}
catch (IOException e)
{
Console.WriteLine("directory file2 failed because:

Directory d = new Directory("e:\\c###");换成
Directory d = new DirectoryInfo("e:\\c###");就可以了。
因为Directory是静态类,不能直接实例化。

Directory d = new Directory("e:\\c###");
Directory 是静态类,无法实例化。利用DirectoryInfo对象实现该功能。

修改为
DirectoryInfo d = new DirectoryInfo("e:\\c###");

Directory d = new Directory("e:\\c###");换成
Directory d = new DirectoryInfo("e:\\c###")

既然是void当然就不需要返回值了,哪还用return,再有其他的错误通过编译器,看看定位在哪行,是什么错误

你编译时有出错提示么?你要实现什么功能?