Flattening a Dictionary of Dictionaries With SelectMany()
<p>I have these dictionaries:</p>

<pre><code>public class CiscoVSAN
    {
private string _VSANName;
    private string _VSANNum;
    public string VSANName{ get{return _VSANName;} set{_VSANName=value;} }
    public string VSANNum{ get{return _VSANNum;} set{_VSANNum=value;} }
  public Dictionary&lt;int, CiscoSwitch&gt; MemberSwitches = new Dictionary&lt;int, CiscoSwitch&gt;();
</code></pre>

<p>}</p>

<pre><code>public Dictionary &lt;int, CiscoVSAN&gt; VSANList = new Dictionary&lt;int, CiscoVSAN&gt;();
</code></pre>

<p>I am trying to replace this foreach</p>

<pre><code> foreach (KeyValuePair&lt;int, CiscoVSAN&gt; vsanpair in this.VSANList)
                {
                   var currSwitchAsEnumerable  = vsanpair.Value.MemberSwitches.Where(cs =&gt; cs.Value.switchName == RemoteSwitchName);
                    if (currSwitchAsEnumerable != null)
                    {
                        //currVSAN.MemberSwitches.Add(DomainID, currSwitchAsEnumerable.FirstOrDefault().Value);
                        currSwitch = currSwitchAsEnumerable.FirstOrDefault().Value;
                        break;
                    }

                }
</code></pre>

<p>With a SelectMany on the outer Dictionary.  I want the first match in MemberSwitches that matches the condition.  Not all VSANs have the same member switches in their respective dictionary. I have tried this:</p>

<pre><code>var selectmany = this.VSANList.SelectMany(cs =&gt; cs.Value).Where( =&gt; cs).Where(cs.Value.SwitchName == RemoteSwitchName).First(); 
</code></pre>

<p>and this:</p>

<pre><code>var selectmany = this.VSANList.Values.SelectMany(cs =&gt; cs.Value).Where( =&gt; cs).Where(cs.Value.SwitchName == RemoteSwitchName).First();
</code></pre>

<p>But each time the compiler tells me it cannot infer the type arguments from usage.  I also tried feeding it a type argument with  after the SelectMany statement but that didn't work either.  Most of the examples I looked at either flattened lists of lists or simple dictionaries.  They also didn't specify any type on the selectmany</p>

<p>Edited to add I tried this:</p>

<pre><code>Dictionary&lt;int, List&lt;string&gt;&gt; mydict = new Dictionary&lt;int, List&lt;string&gt;&gt;();

  var selectlist = mydict.Values.SelectMany(n =&gt; n).ToList();
</code></pre>

<p>and did not get the compiler error about inferring type. So then I tried this, just to flatten the dictionary and turn it to a list:</p>

<pre><code>var selectmany = this.VSANList.Values.SelectMany(vs =&gt; vs).ToList();
</code></pre>

<p>and I get the compiler warning again.  I am not sure what type to specify or how to specify it.</p>
