转换成csharp代码 Private Sub AsyncReadButton_Click() Dim NumItems As Long Dim ServerIndex As Long Dim ServerHandles(10) As Long Dim Values() As Variant Dim Errors() As Long Dim ClientTransactionID As Long Dim ServerTransactionID As Long Dim Qualities() As Variant Dim TimeStamps() As Variant NumItems = 10 ClientTransactionID = 1975 For ServerIndex = 1 to NumItems ‘ set up which items to be read ServerHandles(ServerIndex) = AnOPCItemServerHandles(ServerIndex) Next ServerIndex OneGroup.AsyncRead NumItems, ServerHandles, Errors, ClientTransactionID , ServerTransactionID End Sub
时间: 2024-01-27 12:04:52 浏览: 77
c# 使用模式匹配以及 is 和 as 运算符安全地进行强制转换
下面是将VB代码转换为C#代码的结果:
```
private void AsyncReadButton_Click()
{
long NumItems;
long ServerIndex;
long[] ServerHandles = new long[11];
Array Values;
long[] Errors = new long[11];
long ClientTransactionID;
long ServerTransactionID;
Array Qualities;
Array TimeStamps;
NumItems = 10;
ClientTransactionID = 1975;
for (ServerIndex = 1; ServerIndex <= NumItems; ServerIndex++)
{
// set up which items to be read
ServerHandles[ServerIndex] = AnOPCItemServerHandles(ServerIndex);
}
OneGroup.AsyncRead(NumItems, ServerHandles, ref Errors, ClientTransactionID, ServerTransactionID, out Values, out Qualities, out TimeStamps);
}
```
需要注意的是,由于C#不支持Variant类型,因此需要将Values、Qualities和TimeStamps三个变量声明为Array类型。另外,AsyncRead方法的最后三个参数需要使用out关键字来传递。
阅读全文