Created
February 26, 2013 23:48
-
-
Save kumpera/5043486 to your computer and use it in GitHub Desktop.
This file contains hidden or 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; | |
| 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