- Home /
How to implement and Access Jagged Array C#
I created a Jagged array
public int[,,] npcState = new int[,,] {
{
{0,0}
},{
{1,9,1},{1,0,1},{1,1,1}
},{
{2,2,2},{1,1,1},{1,1,1}
},{
{1,1,1},{10,10}
},{
{8,0},{0,0},{0,0},{0,0}
},{
{10,7},{1,1,1},{1,1,1},{1,1,1},{1,1,1}
},{
{2,2,2}
},{
{1,1,1} ,{1,1,1}
},{
{8,11},{0,0},{0,0},{0,0},{0,0}
},{
{0,1,1},{1,1,1}
}
};
My questions are
1.)How to assign value at run time , if i declare like
public int[,,] npcWayPoints;
2.)How to assign each rows and colomns at run time
3.)How to check array each rows and column using loop like
for(int i =0 ; i < firstDimensionalLength ; i ++){
for(int j =0 ; j < secondDimensionalLength; j ++){
for(int k =0 ; k < thirdDimensionalLength; k ++){
print (npcState[i,j,k]);
}
}
}
If it constant length for all dimensional , it is easy to find elements . But if it dynamic how to find each elements in particular positions.
Answer by AlucardJay · Oct 14, 2016 at 04:30 AM
Your example is a 3D array, not a jagged array : https://en.wikipedia.org/wiki/Jagged_array
DotNetPerls is a great resource for understanding C# : https://www.dotnetperls.com/jagged-array
Check the resources provided by alucard as well as this one:
http://wiki.unity3d.com/index.php/Choosing_the_right_collection_type
Your answer
Follow this Question
Related Questions
jagged array in c# from different sized units 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Double Parse a text file into 2d array or jagged array 1 Answer
Can't create an Collider2D array? 1 Answer