Convert VB to C#

Well, i have tried at least 3 apps, to convert the code, but neither of them worked!

VB CODE:
For Each queryObj As ManagementObject in searcher.Get()
Dim arrVendorSpecific As Byte() = queryObj("VendorSpecific")
MsgBox("Temperature = " & arrVendorSpecific(101))



C# CODE:
foreach (ManagementObject queryObj in searcher.Get())
{
Byte[] arrVendorSpecific = (byte[])(queryObj["VendorSpecific"]);
Console.WriteLine("Temperature = " + arrVendorSpecific(101));
}

This ir the error i get with the C# code:
'arrVendorSpecific' is a 'variable' but is used like a 'method'


ps: the VB code works fine!


Answer this question

Convert VB to C#

  • Keith Newton

    So falo un pouco de portugues... eu sou de Uruguai.

    So I'll explain in english. The reason is that arrays (like Byte[]) are accessed by using indexes within [] in C# and using () in VB... that's it. If you use () in C# the compiler interprets that you trying to call a method, since parameters are placed between parenthesis.

    Feel free to ask any other question that may arise.

    Regards,
    Fernando.


  • polocar

    Which 3 did you try

    Any converter that misses the square brackets on an array access when the array is defined in the sample is not a serious converter.

    David Anton
    www.tangiblesoftwaresolutions.com
    Instant C#: VB to C# converter
    Instant VB: C# to VB converter
    Instant C++: C# to C++ converter, VB to C++ converter
    Instant Python: VB to Python converter



  • SanthaMind

    okey, this worked !

    Po.. pelo nome voce parace ser brasileiro, me da uma explicada, porque o uso de [] ao inves de () !

    If u are not brazillian text above..

    Why did you use [] insted of ()

  • GTH

    foreach (ManagementObject queryObj in searcher.Get())
    {
    Byte[] arrVendorSpecific = (byte[])(queryObj["VendorSpecific"]);
    Console.WriteLine("Temperature = " + arrVendorSpecific[101]);
    }

    Regards,
    Fernando


  • Convert VB to C#