title: Improve performance of TryGetValue
body: <p>I am creating an Excel file using <a href="https://docs.microsoft.com/en-us/office/open-xml/open-xml-sdk?view=openxml-2.8.1" rel="nofollow noreferrer">Open XML SDK</a>. In this process, I have a scenario like below.</p>
  <p>I need to add data into a <code>Dictionary&lt;uint, string&gt;</code> if key is not exists. For that I am using below code.</p>
  <pre><code>var dataLines = sheetData.Elements&lt;Row&gt;().ToList();
  
  for (int i = 0; i &lt; dataLines.Count; i++)
  {
      var x = dataLines[i];
      if (!dataDictionary.TryGetValue(x.RowIndex.Value, out var res)) // 700 seconds, 1,279,999,998 Hit counts
      {
          dataDictionary.Add(x.RowIndex.Value, x.OuterXml);
      }
  }
  </code></pre>
  <p>When I am trying to create an Excel sheet which has rows around 90,000 - 92,000, the line with the <strong>IF</strong> condition in above code consume <strong>700 seconds</strong> to complete. (checked with a performance profiler, also this line has <strong>1,279,999,998 Hit counts</strong>).</p>
  <p>How could I reduce the time the line with the <strong>IF</strong> condition in above code consumes?</p>
  <p>Is there any better way to achive this with less time?</p>