限定二维动态阵列与不同类型的阵列、不同类型、动态

2023-09-06 09:12:39 作者:心痛谁能懂

我想创建不同类型的二维数组一样,我可以添加到该数组两个值其中之一是控件名称和第二个是布尔值。

I want to create two dimension array of different type like I can add to that array two values one of them is controlname and second is boolean value.

推荐答案

您不能这样做。相反,你应该创建一个包含这两个属性的类,那么你可以创建一个类型的数组:

You can't do that. Instead, you should create a class that contains these two properties, then you can create an array of that type:

public class MyClass
{
    public string ControlName {get;set;}
    public bool MyBooleanValue {get;set;}
}

public MyClass[] myValues=new MyClass[numberOfItems];

或者,如安德斯说,使用字典如果属性之一是为了用于执行查找。

Or, as Anders says, use a dictionary if one of the properties is meant to be used to perform lookups.