Skip to content

Instantly share code, notes, and snippets.

View VladimirReshetnikov's full-sized avatar

Vladimir Reshetnikov VladimirReshetnikov

View GitHub Profile
public static string RemoveSubstring(string str, string substr)
{
if (str == null || substr == null)
{
return str;
}
int index = str.IndexOf(substr);
if (index == -1)
class A { bool x = (0 as System.Nullable<int>) < 0; }
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);
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());
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<>) });
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();
#if false
/*
#if false
//*/
#else
// ReSharper thinks this is a real class declaration, but it is a skipped-section
class C
{
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) { }
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[*]
}
using System;
unsafe struct S
{
public void* ptr;
public object obj;
static void Main()
{
S s = default(S);