gpt4 book ai didi

c# - 将 VB.NET 代码转换为 C#

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

我有以下 VB.NET 代码,我正在尝试将其转换为 C#。

Dim decryptedBytes(CInt(encryptedStream.Length - 1)) As Byte

我试过这个:

int tempData = Convert.ToInt32(encryptedStream.Length - 1);
Byte decryptedBytes;
decryptedBytes = decryptedBytes[tempData];

但是得到这个错误信息:

Cannot apply indexing with [] to an expression of type byte.

请注意 VB.NET 代码有效。

最佳答案

使用 SharpDevelop code converter ,您的 VB 代码的输出是:

byte[] decryptedBytes = new byte[Convert.ToInt32(encryptedStream.Length - 1) + 1];

请注意,VB 指定数组的上限,而 C# 指定长度,因此转换器添加了“+ 1”。

我会简化为:

byte[] decryptedBytes = new byte[(int)encryptedStream.Length];

关于c# - 将 VB.NET 代码转换为 C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2804201/

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