1

I 'm not familiar with VB.NET at all. I need to convert this function to C#. Can anyone please give me a hand?

Public Function GetAppGUID(ByVal sectionId As String) As String Dim hexString As String = Nothing Dim i As Integer Dim guidlen As Integer guidlen = 16 If sectionId.Length < guidlen Then sectionId = sectionId & New String(" ".Chars(0), guidlen - sectionId.Length) End If For i = 1 To guidlen hexString = hexString & Hex(Asc(Mid(sectionId, i, 1))) Next GetAppGUID = hexString End Function 
4
  • 3
    could you please explain why you are unable to use an internet search? : developerfusion.com/tools/convert/vb-to-csharp Commented May 25, 2010 at 3:49
  • 2
    It may help if you explain what the purpose of the code is. Commented May 25, 2010 at 4:02
  • 2
    VB.net is basically pseudo code, curious to know what you plan to do with it if you can't translate some pseudo into c# Commented May 25, 2010 at 4:05
  • This is a great opportunity to learn something about another language instead of just having it converted for you. Commented May 25, 2010 at 4:20

4 Answers 4

1

C# solution is below

 private string GetAppGUID(string sectionId) { string hexString = null; int i = 0; int guidLength = 0; guidLength = 16; if (sectionId.Length < guidLength) { sectionId = sectionId + new string(" "[0], guidLength - sectionId.Length); } foreach (char c in sectionId) { int tmp = c; hexString += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString())) } return hexString; } 
Sign up to request clarification or add additional context in comments.

Comments

1

The method uses some VB specific functions that do not have C# equivalents. The functionality could easily be approximated but to use as is, simply add a reference to Microsoft.VisualBasic.

 public string GetAppGUID(string sectionId) { string hexString = null; int i = 0; int guidlen = 0; guidlen = 16; if (sectionId.Length < guidlen) { sectionId = sectionId + new string(' ', guidlen - sectionId.Length); } for (i = 1; i <= guidlen; i++) { hexString = hexString + Microsoft.VisualBasic.Conversion.Hex(Microsoft.VisualBasic.Strings.Asc(Microsoft.VisualBasic.Strings.Mid(sectionId, i, 1))); } return hexString; } 

1 Comment

tools can only go so far - e.g. Chars(0) - this is likely to confuse.
0

These tools don't know some VB functions. There is no Conversion.Hex or Strings.Asc, String.Mid in C#. Any help?

Comments

0

Thanks everyone. I kind of talking rubbish before. The tools are good and yes they convert for you. But is confusing right. The tools use Microsoft.VisualBasic to do the

hexString = hexString + Conversion.Hex(Strings.Asc(Strings.Mid(sectionId, i, 1)));

Which is kind of OK. Does anyone see anything wrong with this?

Thanks

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.