Converting VB.NET code to C#
I have the follwing VB.NET code I am trying to convert to C#.
Dim decryptedBytes(CInt(encryptedStream.Length - 1)) As Byte
I tried this:
int tempData = Convert.ToInt32(encryptedStream.Length - 1);
Byte decryptedBytes;
decryptedBytes = decryptedBytes[tempData];
But got this error message:
Cannot apply indexing with [] to an ex开发者_开发技巧pression of type byte.
Please note that the VB.NET code works.
Using the SharpDevelop code converter, the output for your VB code is:
byte[] decryptedBytes = new byte[Convert.ToInt32(encryptedStream.Length - 1) + 1];
Note that VB specifies for upper bound of the array where C# specifies the length, so the converter added the "+ 1".
I would simplify that to:
byte[] decryptedBytes = new byte[(int)encryptedStream.Length];
byte[] decryptedBytes = new byte[(Int32)encryptedStream.Length];
By the way if you have further problems try this:
http://www.developerfusion.com/tools/convert/vb-to-csharp/
精彩评论