1

What type of array is this JavaScript Array shown? 1-dimensional, 2-dimensional or 3-dimensional? Also what will be the exact representation of this array in C#?

var arr = new Array ([34.01843, -118.491046], [34.006673, -118.486562], [34.009714, -118.480296], [34.010408, -118.473215], [34.01521, -118.474889], [34.022502, -118.480124],
            [34.024423, -118.459868], [34.024885, -118.44871], [34.002368, -118.482828], [34.003791, -118.473001], [34.015922, -118.457422], [34.022147, -118.457894],
            [34.028904, -118.46725], [34.030114, -118.481326], [34.03143, -118.494029], [34.031643, -118.504758], [34.029616, -118.515058], [34.001834, -118.451414]);

The datatypes of values in this array is double.

4
  • Array of items which are each arrays consisting of 2 doubles.. double[][] arr; Commented Dec 5, 2013 at 12:11
  • and why there is a php tag??? Commented Dec 5, 2013 at 12:15
  • 'double' isn't a JavaScript type. A JavaScript variable is not declared explicitly, it is inferred by the runtime. In your snippet the type will be inferred as 'Number' Commented Dec 5, 2013 at 12:16
  • As stated, the exact representation would be an array of arrays of doubles (double[][]), now it seems to me that you want to know something else otherwise you would not add the jquery tag. Do you want to know how to pass this type correctly to C# using jquery? Commented Dec 5, 2013 at 12:26

2 Answers 2

3

That is a jagged array, where each inner array is of length 2.

In C#, you could use:

var arr = new [] {
    new[]{34.01843, -118.491046}, new[]{34.006673, -118.486562}, new[]{34.009714, -118.480296},
    //...
};

which is a double[][]; however, you could also elect to use a double[,] instead (but it would have different semantics):

var arr = new [,] {
    {34.01843, -118.491046}, {34.006673, -118.486562}, {34.009714, -118.480296},
    //...
};
Sign up to request clarification or add additional context in comments.

Comments

1

Well, technically, it doesn't have an "exact representation" in c#, and it depends on how the data is serialized and deserialized at each end.

I'd venture that something like List<Tuple<double,double>> would be a more appropriate datatype at the c# end.

2 Comments

Since in the js you can push to the inner items, and the inner items only have indexed access - I would argue that List<List<double>> would be closer
Sure, but I'm working on the assumption that what's really being described is a list of pairs. I might be wrong.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.