Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining two dimensional Dynamic Array with different types

Tags:

c#

.net

windows

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.

like image 409
Harikrishna Avatar asked Dec 21 '09 10:12

Harikrishna


People also ask

Can you create a 2 dimensional array with different types?

Two-dimensional (2D) arrays are indexed by two subscripts, one for the row and one for the column. Each element in the 2D array must by the same type, either a primitive type or object type.

How do you define two-dimensional array?

The two-dimensional array can be defined as an array of arrays. The 2D array is organized as matrices which can be represented as the collection of rows and columns. However, 2D arrays are created to implement a relational database lookalike data structure.

What are the two types of dimensional array?

Arrays are classified into two types based on their dimensions : single-dimensional and multi-dimensional. Logically, a single-dimensional array represents a linear collection of data, and a two-dimensional array represents a mathematical matrix. Similarly, a multidimensional array has multiple dimensions.

Can we allocate a 2 dimensional array dynamically?

A 2D array can be dynamically allocated in C using a single pointer. This means that a memory block of size row*column*dataTypeSize is allocated using malloc and pointer arithmetic can be used to access the matrix elements.


1 Answers

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.

like image 190
Konamiman Avatar answered Oct 12 '22 12:10

Konamiman