- Home /
Array or List holding 3 floats, multidimensional, Jagged?
Hi,
As below I have 3 arrays holding floats, 7, 7 and 4 .. What I'd like to do is make a list or array (as I know lists are faster) with all these values in one list or array, so I could call 1,1 .. 1,2 .. 1,3 when I want the 1st values and 2,1 .. 2,2 .. 2,3 when I want the 2nd values .. ect .. ect
So would this be a multidimensional array, jagged or ?
What would be the best way to do this?
Would I use something like ..
var aGrid : float[,];
function Start () {
aGrid = new float[ 7, 3 ];
// Init aGrid
// ----------------------
aGrid[ 0, 0 ] = 5;
aGrid[ 0, 1 ] = 2.5;
aGrid[ 0, 2 ] = 1.4;
// ----------------------
aGrid[ 1, 0 ] = 4;
aGrid[ 1, 1 ] = 2;
aGrid[ 1, 2 ] = 1.2;
// ----------------------
aGrid[ 2, 0 ] = 3;
aGrid[ 2, 1 ] = 1.5;
aGrid[ 2, 2 ] = 0.8;
// ----------------------
aGrid[ 3, 0 ] = 2;
aGrid[ 3, 1 ] = 1;
aGrid[ 3, 2 ] = 0.4;
// ----------------------
aGrid[ 4, 0 ] = 2;
aGrid[ 4, 1 ] = 2;
aGrid[ 4, 2 ] = 0;
// ----------------------
aGrid[ 5, 0 ] = 1.6;
aGrid[ 5, 1 ] = 1.6;
aGrid[ 5, 2 ] = 0;
// ----------------------
aGrid[ 6, 0 ] = 1.08;
aGrid[ 6, 1 ] = 1.08;
aGrid[ 6, 2 ] = 0;
// ----------------------
}
Or have I missed it completely ?
Should I put all those numbers in a string then populate the array in a loop?
thanks ..
$$anonymous$$y answers is below, though I wanted to add to your statement of lists being faster than arrays: This is not true in most cases. A list has a lot of overhead, which requires more machine instructions (please correct me if i'm wrong). But I wouldn't worry much about it, then you start getting into micro optimization which is nothing to worry about unless you absolutely need it.
cryingwolf85, Thanks for the input, 90% of what I've read in this forum has pointed to lists being faster, as you say it's micro optimisation I suppose I need not worry .. :)
Thank you for your answer below, as I'm .js I'll look into that, again thanks for the input.
Answer by cryingwolf85 · May 28, 2014 at 04:43 PM
If I were going for simplicity, I would use an object to represent the other 3 numbers. For example:
public class Nums {
public float n1, n2, n3;
public Nums(float n2, float n3, float n3){
this.n1 = n1;
this.n2 = n2;
this.n3 = n3;
}
}
and then create a list like this:
List<Nums> nums = new List<Nums>();
nums.Add(new Nums(1.5f, 1.7f, 3.4f));
For however many nums you want. Hope that helps.
Your answer

Follow this Question
Related Questions
A node in a childnode? 1 Answer
Pick between two floats 2 Answers
how to define spesific object in list? 2 Answers
How do I add Prefabs from Resources folder to List 3 Answers
List of bools assigned to each Gameobject in List/Array 0 Answers