How to Convert this in C#
-
Well! i m having some trouble in writing this piece of code in c#. i m having some type conversion erros pls help me specially the loop portion Dim ids As Object ScannerManager.EnumDeviceIDs(ids) List.Items.Clear() Dim i As Integer For i = LBound(ids) To UBound(ids) List.Items.Add(ids(i)) Next i // signature and prototype information 'EnumDeviceIDs(ref Object) returns array of strings that contain info 'public virtual new void EnumDeviceIDs ( System.Object IDs ) I M new in .net p
-
Well! i m having some trouble in writing this piece of code in c#. i m having some type conversion erros pls help me specially the loop portion Dim ids As Object ScannerManager.EnumDeviceIDs(ids) List.Items.Clear() Dim i As Integer For i = LBound(ids) To UBound(ids) List.Items.Add(ids(i)) Next i // signature and prototype information 'EnumDeviceIDs(ref Object) returns array of strings that contain info 'public virtual new void EnumDeviceIDs ( System.Object IDs ) I M new in .net p
[Message Deleted]
-
Well! i m having some trouble in writing this piece of code in c#. i m having some type conversion erros pls help me specially the loop portion Dim ids As Object ScannerManager.EnumDeviceIDs(ids) List.Items.Clear() Dim i As Integer For i = LBound(ids) To UBound(ids) List.Items.Add(ids(i)) Next i // signature and prototype information 'EnumDeviceIDs(ref Object) returns array of strings that contain info 'public virtual new void EnumDeviceIDs ( System.Object IDs ) I M new in .net p
Hi Its not clear from the code exactly what the EnumDeviceIDS method creates ids as, but i'll assume it is a .NET string array. In which case the code should be something like:
// ids is initially null; object ids = null; ScannerManager.EnumDeviceIDs(ref ids); // we now need to convert ids to an array to let us loop string[] arrids = (string[])ids; List.Items.Clear(); // our for loop can become a nicer foreach foreach(string id in arrids) { List.Items.Add(str); } /* This is all just explanation, so is commented * // signature and prototype information * EnumDeviceIDs(ref Object) * returns array of strings that contain info * 'public virtual new void EnumDeviceIDs ( System.Object IDs ) */
Hope this helps Philip :-D -- modified at 15:18 Saturday 3rd September, 2005