tags:

views:

63

answers:

5

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.

+1  A: 

If you want to lookup/set a boolean by control name, you could use a Dictionary<string, bool>.

Anders Fjeldstad
+2  A: 

You can't to that with an array.

Perhaps you should be using a Dictionary?

A generic dictionary of Dictionary<string,bool> appears to be the kind of thing that will work for your description.

Oded
+2  A: 

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.

Konamiman
A: 

Use Dictionary<string,bool>. If, for some reason, you really need an array, try object[,] and cast its values to the types you want.

marcos
+2  A: 

A dictionary will work for what you are trying to do then.

Dictionary<string, bool> controllerDictionary = new Dictionary<string, bool>();

To set a value

if (controllerDictionary.ContainsKey(controllerName))
    controllerDictionary[controllerName] = newValue;
else
    controllerDictionary.Add(controllerName, newValue);

To get a value

if (controllerDictionary.ContainsKey(controllerName))
    return controllerDictionary[controllerName];
else
    //return default or throw exception
monkey_p
You can just use `controllerDictionary[controllerName] = newValue;`, the `ContainsKey` and `Add` aren't required
Sander Rijken
Ye, that's true, it's only needed for the the get
monkey_p