2 Replies - 1480 Views - Last Post: 17 April 2008 - 09:51 AM Rate Topic: -----

#1 nofear217   User is offline

  • D.I.C Regular
  • member icon

Reputation: 14
  • View blog
  • Posts: 324
  • Joined: 08-November 07

VB to C# conversion

Posted 17 April 2008 - 09:31 AM

I'm trying to convert a program from VB to C# in an effort to give myself a crash course on learning C#. For the most part, things have been going fine but I've run into one problem for which I can't seem to find a solution.
The original VB code looks like this:
Protected Friend Function getMd5Hash(ByVal input As String) As String

		Dim md5Hasher As New MD5CryptoServiceProvider()

		Dim data As Byte() = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input))

		Dim sBuilder As New StringBuilder()

		For i As Integer = 0 To data.Length - 1

			sBuilder.Append(data(i).ToString("x2"))

		Next i

		Return sBuilder.ToString()

	End Function


and I converted it to:
protected internal string getMd5Hash(string input)
		{
			MD5CryptoServiceProvider md5Hasher;

			byte[] data = md5Hasher.ComputeHash(Encoding.Default.GetBytes(input));

			StringBuilder sBuilder = new StringBuilder();

			for (int i = 0; i <= data.Length - 1; i++)
			{
				sBuilder.Append(data(i).ToString("x2"));
			}

			return sBuilder.ToString();
		}



It is throwing the error 'data' is a 'variable' but is used like a 'method' underlining the data in the
sBuilder.Append(data(i).ToString("x2"));



any help or point in the right direction would be greatly appreciated
thanks

Is This A Good Question/Topic? 0
  • +

Replies To: VB to C# conversion

#2 Jayman   User is offline

  • Student of Life
  • member icon

Reputation: 423
  • View blog
  • Posts: 9,532
  • Joined: 26-December 05

Re: VB to C# conversion

Posted 17 April 2008 - 09:43 AM

C# uses brackets instead of parenthesis for arrays.

sBuilder.Append(data[i].ToString("x2"));

Was This Post Helpful? 0
  • +
  • -

#3 nofear217   User is offline

  • D.I.C Regular
  • member icon

Reputation: 14
  • View blog
  • Posts: 324
  • Joined: 08-November 07

Re: VB to C# conversion

Posted 17 April 2008 - 09:51 AM

doh, should have figured it was something simple like that. I'd gotten the declaration correct but not when I used it.

thanks for the help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1