Hi, I have been assigned to Convert a VB.NET project to C# and I got stuck. I am using a class called RsiOPCAuto, but I don't think that I'll have to go into to much detail into explaining how it works. Let's just get on with my issue.
So basicly what i do is grabbing an object from my class using this code:
So far, so good. By adding a watch I can see that oOPCList now have the value {string[1..4]}.
Now I want to put these four strings into a combo box. I do this with a simple for loop:
Event though this object now functions as a string array both the oOPCList.Length and (oOPCList[i]) get errors:
.Length
Error 1 'object' does not contain a definition for 'Length' and no extension method 'Length' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
oOPCList[i]
Error 2 Cannot apply indexing with [] to an expression of type 'object'
I bet it's just the simplest thing but I just can't see it, help is very much appreciated and if there's anything else you need to know be sure to ask :-)
PS. It might be worth mentioning that I have tried some different ways to convert the object to a string array but I continuously get an error telling me that I can not convert system.string[*] to system.string[], which I guess is pretty obvious if it means what I think it means.
This is the VB.NET code that I am converting:
So basicly what i do is grabbing an object from my class using this code:
Code:
public partial class FrmPartialMain : Form { RsiOPCAuto.OPCServer oOpcServer; public FrmPartialMain() { InitializeComponent(); object RsiOPCAuto; object oOPCList; oOpcServer = new RsiOPCAuto.OPCServer(); oOPCList = oOpcServer.GetOPCServers();
Now I want to put these four strings into a combo box. I do this with a simple for loop:
Code:
for (int i = 0; i <= oOPCList.Length; i++) { cboServer.Items.Add(oOPCList[i]); }
.Length
Error 1 'object' does not contain a definition for 'Length' and no extension method 'Length' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)
oOPCList[i]
Error 2 Cannot apply indexing with [] to an expression of type 'object'
I bet it's just the simplest thing but I just can't see it, help is very much appreciated and if there's anything else you need to know be sure to ask :-)
PS. It might be worth mentioning that I have tried some different ways to convert the object to a string array but I continuously get an error telling me that I can not convert system.string[*] to system.string[], which I guess is pretty obvious if it means what I think it means.
This is the VB.NET code that I am converting:
Code:
Friend Class frmPartialMain Inherits System.Windows.Forms.Form Dim oOpcServer As RsiOPCAuto.OPCServer Private Sub frmPartialMain_Load(ByVal eventSender As System.Object, ByVal eventArgs As System.EventArgs) Handles MyBase.Load Dim RsiOPCAuto As Object Dim oOPCList() As Object Dim i As Integer oOpcServer = New RsiOPCAuto.OPCServer oOPCList = oOpcServer.GetOPCServers For i = LBound(oOPCList) To UBound(oOPCList) cboServer.Items.Add(oOPCList(i)) Next i
Comment