Sort List or foreach which would be faster
<p>I have a dictionary of items with the ID as a key.  Those items also have a timespan value.  One function needs to do something with the items where timespan > searchTime.</p>

<p>Would sorting the list fist be faster or would the sorting take as long as the foreach function.  I wish there was a sorted dictionary that allowed you to sort on a different key. </p>

<p>Which would be faster?</p>

<pre><code>List&lt;StatePath&gt; timeSorted = new List&lt;StatePath&gt;();
timeSorted = itemDict.ToList();
timeSorted.Sort((ts1, ts2) =&gt; TimeSpan.Compare(ts1.time, ts2.time));
int i = timeSorted.Count -1;
while((i &gt; 0) &amp;&amp; timeSorted[i].time &gt;= searchTime)
{
  //do something
}
</code></pre>

<p>or </p>

<pre><code>foreach(var curItem in itemDict.Values)
{
  if(curItem.time &gt;= searchTime)
  {
    //do something
  }
}
</code></pre>