Handling a series of named variables of the same type
<p>The following example is bad, because it has code repetition. For example, if we later need to <code>CheckExpirationDate</code> before drinking, we need to add the function call in multiple places. If we need to add <code>charley</code> and <code>stan</code> to the party, the code gets huge quickly.</p>

<pre><code>if (john != designatedDriver)
{
 beer.Open();
 john.Drink(beer);
}
if (bob != designatedDriver)
{
 cider.Open();
 bob.Drink(cider);
}
</code></pre>

<p>The solution could be to build an array of these objects. That's really easy if you need to operate one object at a time. For example, if everyone is passing around a single bottle of beer:</p>

<pre><code>beer.Open();
foreach (Dude i in new Dude[] { john, bob })
{
 i.Drink(beer);
}
</code></pre>

<p>To rewrite the original example, we can use a <code>KeyValuePair</code>. Not particularly pretty, but well worth it for more than two dudes or if the drinking procedure is long enough (wine tasting).</p>

<pre><code>foreach (KeyValuePair&lt;Dude, Booze&gt; i in KeyValuePair&lt;Dude, Booze&gt;[] {
 new KeyValuePair&lt;Dude, Booze&gt;(john, beer),
 new KeyValuePair&lt;Dude, Booze&gt;(bob, cider) })
{
 if (i.Key != designatedDriver)
 {
  i.Value.Open();
  i.Key.Drink(i.Value);
 }
}
</code></pre>

<p><b>But what if we need to operate three or more objects at a time?</b> For example, john drinks beer <i>and</i> eats nachos. We can resort to declaring custom types, but that would make the code dependent on other code somewhere far away. We could put each type in its own array and do a good old <code>for</code> loop and access the objects with indexes, but that would mean creating named arrays (<code>Dude[] dudes = new Dude { john, bob };</code>).</p>

<p>What I'm asking is, <b>is there some fancy C# trick that would let me do this very cleanly and compactly?</b> Anonymous types? Something?</p>
