我在将以下代码片段从 C# 转换为 VB.Net 时遇到问题:
if ((currentItem.Tag as FileSystemKind?) != FileSystemKind.File)
{
if (currentFileName == GOBACK)
currentPath = currentPath.Substring(0, currentPath.Length - Path.GetFileName(currentPath).Length - 1);
else
currentPath = Path.Combine(currentPath, currentFileName);
UpdateControls();
}
else
{
//If it's a file, we should return the selected filename
fileName = Path.Combine(currentPath, currentFileName);
EndOk();
}
问题出在下面一行:
if ((currentItem.Tag as FileSystemKind?) != FileSystemKind.File)
我尝试了两种不同的在线转换器,它们建议我进行以下转换(对于上一行):
第一个:
If (TryCast(currentItem.Tag, FileSystemKind)?) <> FileSystemKind.File Then
第二个:
If TryCast(currentItem.Tag, System.Nullable(Of FileSystemKind)) <> FileSystemKind.File Then
我在 VB.Net 中得到的错误是:
TryCast' operand must be reference type, but 'FileSystemKind?' is a value type.
代码来自一个针对 Net.Compact Framework 2.0 的项目,但我认为大多数应该与普通的 Compact Framework 兼容。
我迷路了。谁能帮帮我?
PS:对题中代码的排版感到抱歉。有没有办法将字体大小更改为较小的?
谢谢!
最佳答案
在 Reflector 中加载编译后的 .dll ,然后将 View 语言更改为 VB,它会为您翻译。
If (DirectCast(TryCast(currentItem.Tag,FileSystemKind?), FileSystemKind) <> FileSystemKind.File) Then
End If
关于c# - .Net - 将代码片段从 C# 转换为 VB.Net 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1251457/