title: Adding values to nested dictionary when key exists
body: <p>I am trying to generate a dictionary of IDs per year per UID, but am struggling to add additional IDs to the nested year/ID dictionary when the year key is already present:</p>
  
  <pre><code>    Dim lstUID_Year_ID As New Dictionary(Of String, Dictionary(Of Integer, Integer))
      Dim intID As Integer = [some ID value taken from dataset according to other variables]
  
                      For Each a As [information] In [dataset]
                          If lstUID_Year_ID.ContainsKey(a.UID) Then
                              If lstUID_Year_ID(a.UID).ContainsKey(a.Year) Then
                                  If Not lstUID_Year_ID(a.UID).Item(a.Year) = intID Then
  'This is where I want to add another value to UID&gt;Year
                                  End If
                              Else
                                  lstUID_Year_ID(a.UID).Add(a.Year, intID)
                              End If
                          Else
                              lstUID_Year_ID.Add(a.UID, New Dictionary(Of Integer, Integer))
                              lstUID_Year_ID(a.UID).Add(a.Year, intID)
                          End If
                      Next
  </code></pre>
  
  <p>So adding another value where a.Year already has values assigned to it is where I am having problems. I can do another <code>lstUID_Year_ID(a.UID).Add(a.Year, intID)</code> as they key is already present, and writing <code>lstUID_Year_ID(a.UID).Item(a.Year)</code> wont allow for another .add clause. So im kind of stuck!</p>
  
  <p>Ive tried writing this with key-value pairs but end up suffering the same problem, i.e. adding values to the nested Year key when it is already present.</p>
  
  <p>Im sure the fix is easy but ive spent a whole day at work toying with it and cant work it out for the life of me.</p>
  
  <p>Any assistance will be greatly appreciated.</p>
  
  <p>Thanks</p>