Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With a bit of reflection, you can turn an anonymous type into a Dictionary&lt;string, object&gt;; Roy Osherove blogs his technique for this here: <a href="http://weblogs.asp.net/rosherove/archive/2008/03/11/turn-anonymous-types-into-idictionary-of-values.aspx" rel="nofollow noreferrer">http://weblogs.asp.net/rosherove/archive/2008/03/11/turn-anonymous-types-into-idictionary-of-values.aspx</a></p> <p>Jacob Carpenter uses anonymous types as a way to initialize immutable objects with syntax similar to object initialization: <a href="http://jacobcarpenter.wordpress.com/2007/11/19/named-parameters-part-2/" rel="nofollow noreferrer">http://jacobcarpenter.wordpress.com/2007/11/19/named-parameters-part-2/</a></p> <p>Anonymous types can be used as a way to give easier-to-read aliases to the properties of objects in a collection being iterated over with a <code>foreach</code> statement. (Though, to be honest, this is really nothing more than the standard use of anonymous types with <a href="http://msdn.microsoft.com/en-us/library/bb397919.aspx" rel="nofollow noreferrer">LINQ to Objects</a>.) For example:</p> <pre><code>Dictionary&lt;int, string&gt; employees = new Dictionary&lt;int, string&gt; { { 1, "Bob" }, { 2, "Alice" }, { 3, "Fred" }, }; // standard iteration foreach (var pair in employees) Console.WriteLine("ID: {0}, Name: {1}", pair.Key, pair.Value); // alias Key/Value as ID/Name foreach (var emp in employees.Select(p =&gt; new { ID = p.Key, Name = p.Value })) Console.WriteLine("ID: {0}, Name: {1}", emp.ID, emp.Name); </code></pre> <p>While there's not much improvement in this short sample, if the <code>foreach</code> loop were longer, referring to <code>ID</code> and <code>Name</code> might improve readability.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload