title: How to use LINQ to find a sum?
body: <p>I have this structure:</p>
  
  <pre><code>private readonly Dictionary&lt;string, Dictionary&lt;string, int&gt;&gt; _storage =
      new Dictionary&lt;string, Dictionary&lt;string, int&gt;&gt;();
  </code></pre>
  
  <p>key: Firmware(string): key: Device(string) : value CountOfUsers (int)</p>
  
  <p>I need to get the total of users for each device, but I really don't know how to do it with LINQ. Already tried a lot of variants. Please, help!</p>
  
  <p>For now, I just use a whole function for it</p>
  
  <pre><code>private XlsRow2 GetTotalPerDevice(Dictionary&lt;string, Dictionary&lt;string, int&gt;&gt; storage)
      {
          XlsRow2 totalPerDeviceRow = new XlsRow2();
          totalPerDeviceRow._Name = "Grand Total";
          totalPerDeviceRow.UseBorders = true;
          foreach (var deviceModel in _allDeviceModels)
          {
              foreach (var firmware in storage)
              {
                  foreach (var device in firmware.Value)
                  {
                      var countOfUsers = 0;
                      if (deviceModel == device.Key)
                      {
                          countOfUsers += device.Value;
  
                          if (!_totalsPerDevice.ContainsKey(deviceModel))
                          {
                              _totalsPerDevice.Add(deviceModel, countOfUsers);
                          }
                          else
                          {
                              _totalsPerDevice[deviceModel] += countOfUsers;
                          }
                      }
                  }
              }
          }
          foreach (var deviceModel in _allDeviceModels)
          {
              if (_totalsPerDevice.ContainsKey(deviceModel))
              {
                  totalPerDeviceRow._AddColumn(_totalsPerDevice.First(k =&gt; k.Key == deviceModel.ToString()).Value.ToString());
              }
              else
              {
                  totalPerDeviceRow._AddColumn("");
              }
          }
          return totalPerDeviceRow;
      }
  </code></pre>