Skip to content

Instantly share code, notes, and snippets.

@kg
Created June 7, 2011 08:26
Show Gist options
  • Save kg/1011897 to your computer and use it in GitHub Desktop.
Save kg/1011897 to your computer and use it in GitHub Desktop.
JSIL Code Sample: Multidimensional Arrays
using System;
public static class Program {
public static void Main (string[] args) {
// [y, x], not [x, y]!
var a = new string[5, 10];
var h = a.GetLength(0);
var w = a.GetLength(1);
for (var y = 0; y < h; y++)
for (var x = 0; x < w; x++)
a[y, x] = String.Format("x={0}, y={1}", x, y);
foreach (var s in a)
Console.WriteLine(s);
}
}
JSIL.MakeStaticClass("Program", true, [], function ($) {
$.Method({Static:true , Public:true }, "Main",
$sig.get(1, null, [$jsilcore.TypeRef("System.Array", [$.String])], []),
function Main (args) {
var a = JSIL.MultidimensionalArray.New($asm01.System.String, 5, 10);
var h = a.length0;
var w = a.length1;
for (var y = 0; y < h; ++y) {
for (var x = 0; x < w; ++x) {
a.Set(y, x, $asm01.System.String.Format("x={0}, y={1}", x, y));
}
}
var array = a;
var upperBound = (array.length0 - 1);
var upperBound2 = (array.length1 - 1);
for (var i = 0; i <= upperBound; ++i) {
for (var j = 0; j <= upperBound2; ++j) {
var s = array.Get(i, j);
$asm01.System.Console.WriteLine(s);
}
}
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment