use*_*313 2 c# arrays indexing properties
我正在创建一个OPC客户端,用户可以读取电子设备的标签.这是通过在OPC组中设置项目来完成的.我想要一个bool []数组的属性来将项目设置为活动或非活动.我需要知道这个属性bool []的哪个索引用于设置属性,所以我可以使用它来激活项目.我可以使用一种方法,但更喜欢一种属性._theGroup是保存项目的OPC组.
private bool[] _ItemActive;
public bool[] itemActive {
get { return _ItemActive; }
set {
if (_theGroup != null) {
int itemIndex = ?? // I don't know how to find property index access by user
int itemHandle = itemHandles[itemIndex]; //uses index to discover handle
_theGroup.SetActiveState(itemHandle, value, out err); // use handle to set item active
}
_ItemActive = value;
}
}
Run Code Online (Sandbox Code Playgroud)
用户会做这样的事情.
opcClient.itemActive[3] = false;
Run Code Online (Sandbox Code Playgroud)
我需要能够发现3并将其插入上面我在我的bool []数组的setter中显示的itemIndex
您可以使用覆盖索引器运算符创建自定义集合,您可以在其中执行自定义逻辑.但创建一个setter方法SetItemActivation(int,bool)似乎是一个更清洁的解决方案.