Welcome to Dream.In.Code
Getting C# Help is Easy!

Join 136,067 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,587 people online right now. Registration is fast and FREE... Join Now!




VB to C# conversion

 
Reply to this topicStart new topic

VB to C# conversion

nofear217
17 Apr, 2008 - 08:31 AM
Post #1

D.I.C Head
Group Icon

Joined: 8 Nov, 2007
Posts: 163



Thanked: 1 times
Dream Kudos: 175
My Contributions
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:
CODE

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:
CODE

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
CODE

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


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

User is offlineProfile CardPM
+Quote Post

Jayman
RE: VB To C# Conversion
17 Apr, 2008 - 08:43 AM
Post #2

Student of Life
Group Icon

Joined: 26 Dec, 2005
Posts: 6,919



Thanked: 42 times
Dream Kudos: 500
Expert In: C#, VB.NET, Java

My Contributions
C# uses brackets instead of parenthesis for arrays.

CODE

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

User is online!Profile CardPM
+Quote Post

nofear217
RE: VB To C# Conversion
17 Apr, 2008 - 08:51 AM
Post #3

D.I.C Head
Group Icon

Joined: 8 Nov, 2007
Posts: 163



Thanked: 1 times
Dream Kudos: 175
My Contributions
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
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/1/08 06:46PM

Live C# Help!

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month