c#转化成vb遇到的问题
大家好:
以下是一段c#代码
string F_name;
string Path = Server.MapPath(".");
DirectoryInfo di=new DirectoryInfo(Path);
foreach(FileSystemInfo fsi in di.GetFileSystem())
{
if (fsi is FileInfo)
{
FileInfo fi = (FileInfo)fsi;
F_name = fi.Name;
}
else
{
di = (Directory)fsi;
F_name = di.Name;
}
}
我试着转化成vb去做,按如下代码:
Dim F_name As String
Dim Path As String = Server.MapPath(".")
Dim di As DirectoryInfo = New DirectoryInfo(path) 'new出一个DirectoryInfo对象用于枚举所有的项
Dim fsi As FileSystemInfo
For Each fsi In di.GetFileSystemInfos() 'GetFileSystemInfos是一个文件夹中所有文件的子目录的强类型FileSystemInfo项数组
'迭代数组中的每一项
Dim fi As FileInfo
If fsi Is FileInfo Then
fi=(FileInfo)fsi
F_name = fi.Name
Else
di=(DirectoryInfo)fsi
F_name = di.Name
End If
一共有四句出现了波浪线。c#里面的di.GetFileSystem()到了vb里面成了di.GetFileSystemInfos() ,
还有fsi Is FileInfo,以及强制类型转换fi=(FileInfo)fsi,di=(DirectoryInfo)fsi都出错。
我不明白在vb里这几句怎样写才合适。请教!谢谢!
------解决方案--------------------
试用这个来转转看:
http://labs.developerfusion.co.uk/convert/csharp-to-vb.aspx
------解决方案--------------------
------解决方案--------------------
你的c#代码本身就是有错误了,转为vb.net稍做了修改,现在是正确的
VB.NET code
Dim F_name As String
Dim Path As String = Server.MapPath(".")
Dim di As New DirectoryInfo(Path)
For Each fsi As FileSystemInfo In di.GetFileSystemInfos()
If (TypeOf (fsi) Is FileInfo) Then
Dim fi As FileInfo = CType(fsi, FileInfo)
F_name = fi.Name
Else
di = CType(fsi, DirectoryInfo)
F_name = di.Name
End If
Next