Skip to content

Instantly share code, notes, and snippets.

@TryJSIL
TryJSIL / StructCopyElimination.cs
Created April 27, 2012 11:13
Struct Copy Elimination
using System;
public static class Program {
public static CustomType ReturnArgument (CustomType arg) {
return arg;
}
public static void Main (string[] args) {
var a = new CustomType(1);
var b = new CustomType(2);
@TryJSIL
TryJSIL / Goto.cs
Created April 27, 2012 11:16
Goto
using System;
public static class Program {
public static void Main (string[] args) {
int i = 0;
a:
i += 1;
Console.WriteLine("a");
for (; i < 16; i++) {
@TryJSIL
TryJSIL / GenericsAndNestedTypes.cs
Created April 27, 2012 11:16
Generic Nested Types
using System;
public class Program {
public static void Main (string[] args) {
Console.WriteLine(
Battlestar<object>.instance.commander
);
}
}
@TryJSIL
TryJSIL / MultiDimArrays.cs
Created April 27, 2012 11:17
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++)
@TryJSIL
TryJSIL / Closures.cs
Created April 27, 2012 11:17
Closures
using System;
public static class Program {
public static void Main (string[] args) {
int x = 1;
string y = "y";
Func<string> a = () => {
return String.Format("x={0}, y={1}", x, y);
};
@TryJSIL
TryJSIL / DynamicDOM.cs
Created April 27, 2012 11:33
Dynamic DOM
using System;
using JSIL;
using JSIL.Meta;
public static class Program {
public static int x = 10;
public static int y = 20;
public static void Main () {
dynamic document = Builtins.Global["document"];
@TryJSIL
TryJSIL / events1.cs
Created April 27, 2012 11:34
MSDN Events Tutorial
// http://msdn.microsoft.com/en-us/library/aa645739%28v=vs.71%29.aspx
// events1.cs
using System;
namespace MyCollections
{
using System.Collections;
// A delegate type for hooking up change notifications.
public delegate void ChangedEventHandler(object sender, EventArgs e);
@TryJSIL
TryJSIL / NBody.cs
Created April 27, 2012 12:43
NBody Benchmark
/* The Computer Language Benchmarks Game
http://shootout.alioth.debian.org/
contributed by Isaac Gouy, optimization and use of more C# idioms by Robert F. Tobler
*/
using System;
public static class Program {
public static void Main () {
@TryJSIL
TryJSIL / Enums.cs
Created April 27, 2012 12:44
Enums
using System;
public static class Program {
public enum SimpleEnum {
A,
B = 3,
C,
D = 10
}
@TryJSIL
TryJSIL / SealedMethods.cs
Created April 27, 2012 12:52
Sealed Methods
using System;
public class Foo {
public void Func1 () {
Console.Write("F1 ");
}
public virtual void Func2 () {
Console.Write("F2 ");
this.Func1();