将VB.NET代码转换为C#

时间:2010-05-10 16:01:33

标签: c# vb.net

我有以下的VB.NET代码,我试图转换为C#。

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

我试过了:

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

但收到此错误消息:

  

无法将带有[]的索引应用于byte类型的表达式。

请注意VB.NET代码有效。

2 个答案:

答案 0 :(得分:3)

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

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

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

我会简化为:

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

答案 1 :(得分:1)

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

顺便说一下,如果你有其他问题,试试这个:

http://www.developerfusion.com/tools/convert/vb-to-csharp/