c# - .Net - 将代码片段从 C# 转换为 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(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/

相关文章:

c# - (char)int 从哪里得到它的符号?

c# - 从 ASP.NET 客户端排除 WCF 故障 -- 帮助!

c# - 以编程方式分离 SQL Server 数据库以复制 mdf 文件

c# - using关键字和IDisposable接口(interface)有什么关系?

vb.NET SaveAs 不保存所有 Excel 数据

vb.net - VB.Net-无法在Access中创建字段 “password”

c# - 如何确定 Console.Out 是否已重定向到文件?

c# - FTP 目录列表返回为 HTML 而不是简单的 Linux ls 输出

c# - 2nd Page_Load 上的 NullReferenceException

mysql - 使用 BulkCopy 时出错(无法读取结果集)