Created
June 7, 2011 08:13
-
-
Save kg/1011883 to your computer and use it in GitHub Desktop.
JSIL Code Sample: ref parameters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
public static class Program { | |
public static void Increment (ref int x) { | |
x += 1; | |
} | |
public static void Main (string[] args) { | |
Func<int, int> inc = (i) => { | |
Increment(ref i); | |
return i; | |
}; | |
Console.WriteLine("{0}, {1}", inc(1), inc(2)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JSIL.MakeStaticClass("Program", true, [], function ($) { | |
$.Method({Static:true , Public:true }, "Increment", | |
$sig.get(1, null, [$jsilcore.TypeRef("JSIL.Reference", [$.Int32])], []), | |
function Increment (/* ref */ x) { | |
++x.value; | |
} | |
); | |
$.Method({Static:true , Public:true }, "Main", | |
$sig.get(2, null, [$jsilcore.TypeRef("System.Array", [$.String])], []), | |
function Main (args) { | |
var inc = function ($i) { | |
var i = new JSIL.Variable($i); | |
$asm00.Program.Increment(/* ref */ i); | |
return i.value; | |
}; | |
$asm01.System.Console.WriteLine( | |
"{0}, {1}", | |
inc(1), | |
inc(2) | |
); | |
} | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment