.Net-将代码段从C#转换为VB.Net时出现问题

.Net-将代码段从C#转换为VB.Net时出现问题,c#,.net,vb.net,C#,.net,Vb.net,我在将以下代码段从C#转换为VB.Net时遇到问题: if ((currentItem.Tag as FileSystemKind?) != FileSystemKind.File) { if (currentFileName == GOBACK) currentPath = currentPath.Substring(0, currentPath.Length - Path.GetFileName(

我在将以下代码段从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,FileSystemKind)?)FileSystemKind.File然后
第二个:

If TryCast(currentItem.Tag, System.Nullable(Of FileSystemKind)) <> FileSystemKind.File Then
如果TryCast(currentItem.Tag,System.Nullable(属于FileSystemKind))FileSystemKind.File,则
我在VB.Net中遇到的错误是:

TryCast操作数必须是引用类型,但“FileSystemKind”是值类型

代码来自一个针对Net.compactframework2.0的项目,但我认为大多数应该与普通的compactframework兼容

我迷路了。有人能帮我吗

PS:我对问题中的代码布局感到抱歉。有没有办法把字体改小一点


谢谢

如果currentItem.Tag始终是FileSystemKind类型,您可以尝试

If TypeOf(currentItem.Tag) Is FileSystemKind AndAlso CType(currentItem.Tag, FileSystemKind) = FileSystemKind.File Then

If (DirectCast(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then

        If TypeOf (currentItem.Tag) Is FileSystemKind Then
            If (DirectCast(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then
            End If
        Else
            ' handle different types
        End If

如果(DirectCast(currentItem.Tag,FileSystemKind)FileSystemKind.File),则
如果currentItem.Tag不总是FileSystemKind类型,您可以尝试


If (DirectCast(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then

        If TypeOf (currentItem.Tag) Is FileSystemKind Then
            If (DirectCast(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then
            End If
        Else
            ' handle different types
        End If

如果TypeOf(currentItem.Tag)是FileSystemKind,那么
如果(DirectCast(currentItem.Tag,FileSystemKind)FileSystemKind.File),则
如果结束
其他的
"分门别类",
如果结束
您还可以使用“CType”将变量对象“currentItem.Tag”的类型转换或强制转换为FileSystemKind类型


If (CType(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then

如果(CType(currentItem.Tag,FileSystemKind)FileSystemKind.File),则

如果currentItem.Tag始终是FileSystemKind类型,您可以尝试


If (DirectCast(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then

        If TypeOf (currentItem.Tag) Is FileSystemKind Then
            If (DirectCast(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then
            End If
        Else
            ' handle different types
        End If

如果(DirectCast(currentItem.Tag,FileSystemKind)FileSystemKind.File),则
如果currentItem.Tag不总是FileSystemKind类型,您可以尝试


If (DirectCast(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then

        If TypeOf (currentItem.Tag) Is FileSystemKind Then
            If (DirectCast(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then
            End If
        Else
            ' handle different types
        End If

如果TypeOf(currentItem.Tag)是FileSystemKind,那么
如果(DirectCast(currentItem.Tag,FileSystemKind)FileSystemKind.File),则
如果结束
其他的
"分门别类",
如果结束
您还可以使用“CType”将变量对象“currentItem.Tag”的类型转换或强制转换为FileSystemKind类型


If (CType(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then

如果(CType(currentItem.Tag,FileSystemKind)FileSystemKind.File),则

在中加载已编译的.dll,然后将视图语言更改为VB,它将为您翻译

 If (DirectCast(TryCast(currentItem.Tag,FileSystemKind?), FileSystemKind) <> FileSystemKind.File) Then
    End If
If(DirectCast(TryCast(currentItem.Tag,FileSystemKind?),FileSystemKind)FileSystemKind.File)然后
如果结束

在中加载已编译的.dll,然后将视图语言更改为VB,它将为您翻译

 If (DirectCast(TryCast(currentItem.Tag,FileSystemKind?), FileSystemKind) <> FileSystemKind.File) Then
    End If
If(DirectCast(TryCast(currentItem.Tag,FileSystemKind?),FileSystemKind)FileSystemKind.File)然后
如果结束

他不是在测试它是否为枚举类型,而是在测试它是否为枚举值。他不是在测试它是否为枚举类型,而是在测试它是否为枚举值。roygbiv:您建议的“if(CType(currentItem.Tag,FileSystemKind)FileSystemKind.File)Then”语句解决了所有问题。谢谢。罗伊格比夫:你建议的声明“如果(CType(currentItem.Tag,FileSystemKind)FileSystemKind.File)那么”解决了所有问题。谢谢。是的,那当然是我的建议,但你比我强。嘿,米凯尔:是的,那是我没想到的另一个转换器。下次遇到类似问题时,我会记住这一点。它也适用于其他.Net语言。它的输出比建议的解决方案还要短。投我一票:)是的,那当然是我的建议,但你比我强。嘿,米凯尔:是的,那是另一个我没想到的转换器。下次遇到类似问题时,我会记住这一点。它也适用于其他.Net语言。它的输出比建议的解决方案还要短。投票支持我:)