gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 19:36:32 25 4
gpt4 key购买 nike

我在将以下代码片段从 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com