Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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 / Nullables.cs
Created April 27, 2012 12:55
Nullables
using System;
public static class Program {
public static void PrintNullable (int? i) {
if (i.HasValue)
Console.Write("{0} ", i.Value);
else
Console.Write("null ");
}
@TryJSIL
TryJSIL / BinaryTrees.cs
Created April 27, 2012 12:59
Tree Benchmark
/* The Computer Language Benchmarks Game
http://shootout.alioth.debian.org/
contributed by Marek Safar
*/
using System;
public static class Program {
const int minDepth = 4;
@TryJSIL
TryJSIL / Interfaces.cs
Created April 27, 2012 13:06
Interfaces
using System;
public interface I {
void Foo ();
}
public class A : I {
public void Foo () {
Console.WriteLine("A");
}