Skip to content

Instantly share code, notes, and snippets.

@kg
Created June 7, 2011 07:04
Show Gist options
  • Save kg/1011800 to your computer and use it in GitHub Desktop.
Save kg/1011800 to your computer and use it in GitHub Desktop.
JSIL Code Sample: ForEach
using System;
using System.Collections.Generic;
public static class Program {
public static void Main (string[] args) {
var array = new[] { 1, 2, 4, 8, 16 };
foreach (var i in array)
Console.WriteLine(i);
var list = new List<int>(array);
foreach (var j in list)
Console.WriteLine(j);
}
}
JSIL.MakeStaticClass("Program", true, [], function ($) {
$.Method({Static:true , Public:true }, "Main",
$sig.make(1747428, null, [$jsilcore.TypeRef("System.Array", [$.String])], []),
function Program_Main (args) {
var array = JSIL.Array.New($asm01.System.Int32, [1, 2, 4, 8, 16]);
var array2 = array;
for (var k = 0; k < array2.length; ++k) {
$asm01.System.Console.WriteLine(array2[k]);
}
var list = (new JSIL.MethodSignature(null, [$asm01.TypeRef("System.Collections.Generic.IEnumerable`1", [$.Int32])], [])).Construct($asm01.System.Collections.Generic.List$b1.Of($asm01.System.Int32), array);
for (var a$0 = list._items, i$0 = 0, l$0 = list._size; i$0 < l$0; i$0++) {
var j = a$0[i$0];
$asm01.System.Console.WriteLine(j);
}
}
);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment