Created
August 10, 2016 02:41
-
-
Save gulbanana/c608f1a09145eee45d175e7c139fa3e3 to your computer and use it in GitHub Desktop.
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.Dynamic; | |
class LookImUsingRuby | |
{ | |
static void Main(string[] args) | |
{ | |
var x = new { Foo = 1, Bar = "data" }; // anonymous object! | |
Console.WriteLine(x.Foo); // this is type-checked because within this method, we know Foo exists | |
PrintFoo(x); // no typechecking beyond this point. it works, though | |
dynamic y = new ExpandoObject(); // this one doesn't even have a preset structure lol | |
y.Foo = "???"; // a different type to x.Foo | |
PrintFoo(y); // and yet this still works | |
} | |
static void PrintFoo(dynamic x) | |
{ | |
Console.WriteLine(x.Foo); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment