An Array which contains more than one rows and more than one columns is multi dimensional Array
Working with MultiDimentional Array:-
Syntax:
Data
Type [,] Array name=new Data Type [Rowsize, column size];
Ex:
int[
, ]A=new int[4,3]
A[0,0]=95; A[0,1]=19; A[0,2]=29; A[1,0]=39; A[1,1]=49; A[1,2]=59;
A[2,0]=69; A[2,1]=79; A[2,2]=89; A[3,0]=99; A[3,1]=88; A[3,3]=18;
A[2,0]=69; A[2,1]=79; A[2,2]=89; A[3,0]=99; A[3,1]=88; A[3,3]=18;
Syntax:
Data
Type[ , ] Array name=new Data Type
[Rowsize, column size]{{Row1 Elements},{Row2 Elements},……..};
int[ , ] A = new int[4,3] { { 95,
19, 29 }, { 39, 49, 59 }, { 69, 79, 89 }, { 99, 88, 18 }};
Example:-
using System;
using
System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CAArrays
{
class ClsMDArray
{
static
void Main()
{
int[,]
A = new int[4,3]
{ { 95, 19, 29 }, { 39, 49, 59 }, { 69, 79, 89 }, { 99, 88, 18 } };
Console.WriteLine("Elements of Multidimensional Array Are");
for
(int R = 0; R < 4; R++)
{
for
(int c = 0; c < 3; c++)
{
Console.Write(A[R,c]
+"
");
}
Console.WriteLine();
}
Console.ReadLine();
}
}
}
|
Output:-
No comments:
Post a Comment