This file contains 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; | |
using System.Runtime.InteropServices; | |
public static class Program { | |
public static unsafe void Main (string[] args) { | |
var bytes = new byte[8]; | |
fixed (byte* pBytes = bytes) { | |
var pStruct = (MyStruct*)pBytes; | |
*pStruct = new MyStruct { |
This file contains 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 unsafe void Main (string[] args) { | |
var ints = new int[] { 0, 1, 2, 3 }; | |
fixed (int* pInts = ints) { | |
var pBytes = (byte*)pInts; | |
for (var i = 0; i < (ints.Length * 4); i++) |
This file contains 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 class Program { | |
public static void Main () { | |
var i = 0; | |
var x = 1L; | |
Console.WriteLine("Left shift"); | |
Console.WriteLine(x); | |
Console.WriteLine("{0} {1}", 1, Format(x << 1)); | |
This file contains 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; | |
using System.Collections; | |
using System.Collections.Generic; | |
public static class Program { | |
public static IEnumerable<int> OneToNine { | |
get { | |
for (int i = 0; i < 10; i++) | |
yield return i; | |
} |
This file contains 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; | |
using System.Reflection; | |
using System.Collections.Generic; | |
public static class Program { | |
public static void Main (string[] args) { | |
Common.Util.ListMembers<MethodInfo>( | |
typeof(T), | |
BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | |
); |
This file contains 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 interface I { | |
void Foo (); | |
} | |
public class A : I { | |
public void Foo () { | |
Console.WriteLine("A"); | |
} |
This file contains 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
/* The Computer Language Benchmarks Game | |
http://shootout.alioth.debian.org/ | |
contributed by Marek Safar | |
*/ | |
using System; | |
public static class Program { | |
const int minDepth = 4; |
This file contains 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 class GenericClass<T> { | |
public virtual void Method (T value) { | |
Console.WriteLine("GenericClass<{0}>.Method({1})", typeof(T), value); | |
} | |
} | |
public class MyClass<T> : GenericClass<T> { | |
public override void Method (T value) { |
This file contains 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 Main (string[] args) { | |
Action<int> a = | |
(i) => Console.WriteLine("a({0})", i); | |
Action<int> b = | |
(i) => Console.WriteLine("b({0})", i); | |
Action<int> c = (Action<int>)Delegate.Combine(a, b); |
This file contains 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 PrintNullable (int? i) { | |
if (i.HasValue) | |
Console.Write("{0} ", i.Value); | |
else | |
Console.Write("null "); | |
} |
NewerOlder