代码之家  ›  专栏  ›  技术社区  ›  moster67

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

  •  1
  • moster67  · 技术社区  · 16 年前

    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
    

    谢谢!

    3 回复  |  直到 16 年前
        1
  •  3
  •   Mikael Svenson    16 年前

    在中加载已编译的.dll Reflector

     If (DirectCast(TryCast(currentItem.Tag,FileSystemKind?), FileSystemKind) <> FileSystemKind.File) Then
        End If
    
        2
  •  2
  •   user113476 user113476    16 年前

    如果当前项目。标签的类型始终为FileSystemKind,您可以尝试

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

    如果当前项目。标签是 始终为FileSystemKind类型,您可以尝试

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

    您还可以使用“CType”将变量对象“currentItem.Tag”的类型转换或强制转换为FileSystemKind类型

    
    If (CType(currentItem.Tag, FileSystemKind) <> FileSystemKind.File) Then
    
        3
  •  1
  •   ZippyV    16 年前
    If TypeOf(currentItem.Tag) Is FileSystemKind AndAlso CType(currentItem.Tag, FileSystemKind) = FileSystemKind.File Then