user2594323
user2594323

Reputation: 1

Define size of 2 dimensional array by parameter

I want to define some this:

int m=5;

int [,] matrix=new int[4,m];

Is it possible?

Upvotes: 0

Views: 112

Answers (2)

Shyam sundar shah
Shyam sundar shah

Reputation: 2523

I have constructed array name is matrix and has dimension 3*3. You can change this code as your requirement.

int m=3
int [,] matrix = int [3,m] = {  
{0, 1, 2, 3} ,   
{4, 5, 6, 7} ,  
{8, 9, 10  }   
 };

Upvotes: 0

Brett Sanderson
Brett Sanderson

Reputation: 308

What you have works for fixed sized. If you want a dynamic matrix then use something like

var matrix = new List<List<int>>();

Upvotes: 1

Related Questions