I am converting a VB.NET project to C# and I got stuck on this if-loop, could anyone help me convert this? I am assuming that i’ll need to use the GetType()-method for this but I’m not sure how.
The Loop:
Private Sub oOpcGroup_DataChange(ByVal TransactionID As Integer, ByVal NumItems As Integer, ByRef ClientHandles() As Integer, ByRef ItemValues() As Object, ByRef Qualities() As Integer, ByRef TimeStamps() As Date)
Dim i As Integer
For i = 1 To NumItems
If VarType(ItemValues(i)) And Not VariantType.Array Then
txtSubValue.Text = ItemValues(i)
Else
MsgBox("Data type return error, returned array, expected single item", MsgBoxStyle.Critical, "Data Change Error")
Exit Sub
End If
Next i
Exit Sub
End Sub
This is what I have so far:
void oOpcGroup_DataChange(int TransactionID, int NumItems, ref Array ClientHandles, ref Array ItemValues, ref Array Qualities, ref Array TimeStamps) //Events OPCGroup
{
for (int i = 0; i < NumItems; i++)
{
if(){
}
else
{
MessageBox.Show("Expected single item.", "Data type return error.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}
Here is what I came up with, using the GetType() instead of the Information.VarType.
I did replace the MsgBox method call with a call to System.Windows.Forms.MessageBox.Show.