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
public static string RemoveSubstring(string str, string substr) | |
{ | |
if (str == null || substr == null) | |
{ | |
return str; | |
} | |
int index = str.IndexOf(substr); | |
if (index == -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
class A { bool x = (0 as System.Nullable<int>) < 0; } |
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; | |
static class Program | |
{ | |
static void Main() | |
{ | |
Action action = ((object)0).Foo; | |
if (action.Target != null && action.Method.IsStatic) | |
{ | |
Console.WriteLine(action.Target.GetType().IsValueType); |
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; | |
class Program | |
{ | |
static void Main() | |
{ | |
var allocate = typeof (RuntimeTypeHandle).GetMethod("Allocate", (BindingFlags) 40); | |
var open = allocate.Invoke(null, new[] {typeof (C<>.E)}); | |
Console.WriteLine(open.GetType()); |
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.Generic; | |
using System.Reflection; | |
class Program | |
{ | |
static void Main() | |
{ | |
var allocate = typeof(RuntimeTypeHandle).GetMethod("Allocate", (BindingFlags)40); | |
var open = allocate.Invoke(null, new[] { typeof(IList<>) }); |
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
class Program | |
{ | |
// What argument do you need to provide to this method so that it returns true? | |
public static bool AreYouNuts<T>(T[] array) | |
{ | |
if (array == null || array.Length == 0) | |
return false; | |
var local = (T[]) array.Clone(); |
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
#if false | |
/* | |
#if false | |
//*/ | |
#else | |
// ReSharper thinks this is a real class declaration, but it is a skipped-section | |
class C | |
{ | |
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 N; // This using directive is unused, but cannot be simply removed | |
static class C | |
{ | |
static void Ex(this string x) { } | |
static void Foo(Action<string> x, int y) { } | |
static void Foo(Action<string> x, string y) { } | |
static void Foo(Action<string> x, object y) { } | |
static void Foo(Action<int> x, int y) { } |
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; | |
class Program | |
{ | |
static void Main() | |
{ | |
Array a = Array.CreateInstance(typeof(int), new[]{1}, new[]{1}); | |
Console.WriteLine(a is int[]); // False | |
Console.WriteLine(a.GetType()); // System.Int32[*] | |
} |
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; | |
unsafe struct S | |
{ | |
public void* ptr; | |
public object obj; | |
static void Main() | |
{ | |
S s = default(S); |
OlderNewer