Skip to content

Commit 0c57262

Browse files
committed
Calling methods that may or may not exist
1 parent 4e2d40f commit 0c57262

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

dynamic_Deep_Dive/02-Intermediate/Medium.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public static void Run()
3434
user.SayHi = new Action(() => Console.WriteLine("Hi from Sam!"));
3535
user.SayHi();
3636

37+
// Calling methods that may or may not exist
38+
39+
dynamic maybe = new { Message = "I exist!" };
40+
// Will throw RuntimeBinderException if method does not exist
41+
Console.WriteLine(maybe.Message);
3742

3843
#endregion
3944
}

0 commit comments

Comments
 (0)