How does assignment to dynamic object work in C#?
<p>In ASP.NET MVC the property <code>ViewBag</code> is of type dynamic.</p>

<p><a href="http://www.asp.net/mvc/tutorials/mvc-4/getting-started-with-aspnet-mvc4/adding-a-view" rel="nofollow">Throught the code</a>, various "properties" of <code>ViewBag</code> are assigned to: </p>

<pre><code>ViewBag.Message = "Hello world";
ViewBag.Title = "Page title";
</code></pre>

<p>How does this work? From reading the <a href="http://msdn.microsoft.com/en-us/library/dd264736.aspx" rel="nofollow">docs</a> I get that <code>ViewBag</code> itself can by anything, but why (or how) does assigning something to a "member" of dynamic type work?</p>

<p>Here is how <code>ViewBag</code> is defined in <code>public abstract class ControllerBase : IController</code> class:</p>

<pre><code> [Dynamic]
 public dynamic ViewBag { get; }
 //
 // Summary:
 //     Gets or sets the dictionary for view data.
 //
 // Returns:
 //     The dictionary for the view data.
 public ViewDataDictionary ViewData { get; set; }
</code></pre>

<p>Just curious.</p>

<p><em>Relevant question:</em> <a href="http://stackoverflow.com/questions/6735423/where-can-i-find-the-official-documentation-for-dynamicviewdatadictionary">Where can I find the official documentation for DynamicViewDataDictionary?</a></p>
