初学者的问题,Directory和CreateSubdirectory报错(50分)

  • 主题发起人 主题发起人 nickname
  • 开始时间 开始时间
N

nickname

Unregistered / Unconfirmed
GUEST, unregistred user!
using System;
using System.IO;
class DirectoryTest
{
public static void Main()
{
Directory d=new Directory("c://c#");
Directory d1;
Directory d2;
try
{
d1=d.CreateSubdirectory("file1");
}
catch(IOException e)
{
Console.WriteLine("directory fiel1 failed because:{0}",e);
return;
}
try
{
d2=d.CreateSubdirectories("file1//file2");
}
catch(IOException e)
{
Console.WriteLine("directory file2 failed because :{0}",e);
return;
}
Console.WriteLine("Create diectory successfully!");
}
}
 
请问这段程序有错吗?
 
应该用DirectoryInfo,而不是Directory;
using System;
using System.IO;
class DirectoryTest
{
public static void Main()
{
DirectoryInfo d=new DirectoryInfo("c://c#");
DirectoryInfo d1;
DirectoryInfo d2;
try
{
d1=d.CreateSubdirectory("file1");
}
catch(IOException e)
{
Console.WriteLine("directory fiel1 failed because:{0}",e);
return;
}
try
{
d2=d.CreateSubdirectory("file1//file2");
}
catch(IOException e)
{
Console.WriteLine("directory file2 failed because :{0}",e);
return;
}
Console.WriteLine("Create diectory successfully!");
}
}[:D]
 
接受答案了.
 
后退
顶部