title: VB.NET and LINQ query on a dictionary
body: <p>I need a simple LINQ query on VB.NET on the dictionary below, but I'm really new to the subject so I need your help.</p>
  
  <pre><code>    Protected Sub Page_Load(sender As Object, e As System.EventArgs) Handles Me.Load
          Dim appEnums As New Dictionary(Of Integer, String)
  
          appEnums.Add(1, "www.eva.com")
          appEnums.Add(2, "www.eva2.com")
          appEnums.Add(4, "www.evanetwork.com")
          appEnums.Add(5, "www.eva3.com")
          appEnums.Add(6, "www.eva4.com")
          appEnums.Add(7, "www.eva5.com")
          appEnums.Add(8, "www.eva6.com")
          appEnums.Add(9, "www.eva1.com")
          appEnums.Add(10, "www.eva7.com")
  
          Dim startSite As Integer = 1
          Dim mainSite As Integer = 4
          Dim returnSite As Integer = 5
      End Sub
  </code></pre>
  
  <p>What I need here is to retrieve a SINGLE website (dictionary value of string type) or NOTHING (if the query cannot find an affordable result) given those rules:</p>
  
  <ul>
  <li>The dictionary key (integer) must be greater than startSite and not equal to mainSite or returnSite (both must be exluded from the result)</li>
  </ul>
  
  <p>Any hint?</p>
  
  <p>EDIT: thanks for the replies so far! I'm not sure they would work btw have to test them, at a first glance there is something odd.</p>
  
  <p>I found a solution myself and it works perfectly (can't believe it) but I think there should be a more "elegant" way to it (in vb.net always). waiting for suggestions :) </p>
  
  <pre><code>        Dim resultSite As String
  
          Try
              resultSite = appEnums.Where(Function(x) x.Key &gt; startSite _
              AndAlso x.Key &lt;&gt; mainSite AndAlso x.Key &lt;&gt; returnSite) _
              .OrderBy(Function(x) x.Key).Select(Function(x) x.Value).First()
          Catch
              resultSite = Nothing
          End Try
  </code></pre>