繁体   English   中英

将VB.NET代码转换为C#

[英]Converting VB.NET code to C#

我有以下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代码有效。

使用SharpDevelop代码转换器 ,VB代码的输出是:

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

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

我会简化为:

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

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

顺便说一句,如果你有进一步的问题,试试这个:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM