Skip to content

Instantly share code, notes, and snippets.

@kumpera
Created February 26, 2013 23:48
Show Gist options
  • Select an option

  • Save kumpera/5043486 to your computer and use it in GitHub Desktop.

Select an option

Save kumpera/5043486 to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
interface IFoo {}
class Bar : MarshalByRefObject {
public void Tst () {}
public int field;
}
class Driver : IFoo {
static void Main ()
{
var f = new Driver ();
Console.WriteLine ("{0} == f", f is ICollection);
Console.WriteLine ("{0} == t", f is IFoo);
try {
var g = (IFoo)f;
Console.WriteLine ("cast/1 ok");
}catch (InvalidCastException) {Console.WriteLine ("cast/1 bad"); }
try {
var h = (ICollection)f;
Console.WriteLine ("cast/2 bad");
}catch (InvalidCastException) {Console.WriteLine ("cast/2 ok"); }
var b = new Bar ();
b.Tst ();
Console.WriteLine (b.field);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment