我有以下 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];
