title: Translate C# Linq to VB
body: <p>I could use some help converting this C# line of code to VB. I am very new to Linq and am having trouble with the syntax...</p>
  
  <pre><code>var rows = GridView1.Rows.Cast&lt;GridViewRow&gt;().Where(a =&gt; a != row).ToList();
  </code></pre>
  
  <p>I have tried a number of online conversion tools and none of them have gotten it right either.</p>
  
  <p>UPDATE:
  Here is the full code block....</p>
  
  <pre><code>protected void MoveGridViewRows(object sender, EventArgs e)  {      
      Button btnUp = (Button)sender;      
      GridViewRow row = (GridViewRow)btnUp.NamingContainer;      
      // Get all items except the one selected      
      var rows = GridView1.Rows.Cast&lt;GridViewRow&gt;().Where(a =&gt; a != row).ToList();      
      switch (btnUp.CommandName)      
      {          
           case "Up":              
           //If First Item, insert at end (rotating positions)              
                if (row.RowIndex.Equals(0))
                    rows.Add(row);              
                else                 
                    rows.Insert(row.RowIndex - 1, row);              
                    break;          
           case "Down":              
           //If Last Item, insert at beginning (rotating positions)              
                if (row.RowIndex.Equals(GridView1.Rows.Count - 1))                  
                    rows.Insert(0, row);              
                else                 
                    rows.Insert(row.RowIndex + 1, row);              
                    break;      
           }      
           GridView1.DataSource = rows.Select(a =&gt; new     
           {          
                FirstName = ((TextBox)a.FindControl("txtFirstName")).Text,          
                LastName = ((TextBox)a.FindControl("txtLastName")).Text,      
           }).ToList();      
           GridView1.DataBind();  
  } 
  </code></pre>
  
  <p>The specific error in VS on compile is....</p>
  
  <p>Error   11  Overload resolution failed because no accessible 'Where' can be called with these arguments:
      Extension method 'Public Function Where(predicate As System.Func(Of System.Web.UI.WebControls.GridViewRow, Integer, Boolean)) As System.Collections.Generic.IEnumerable(Of System.Web.UI.WebControls.GridViewRow)' defined in 'System.Linq.Enumerable': Nested function does not have the same signature as delegate 'System.Func(Of System.Web.UI.WebControls.GridViewRow, Integer, Boolean)'.
      Extension method 'Public Function Where(predicate As System.Func(Of System.Web.UI.WebControls.GridViewRow, Boolean)) As System.Collections.Generic.IEnumerable(Of System.Web.UI.WebControls.GridViewRow)' defined in 'System.Linq.Enumerable': Operator '&lt;>' is not defined for types 'System.Web.UI.WebControls.GridViewRow' and 'System.Web.UI.WebControls.GridViewRow'.  </p>
  
  <p>Also...</p>
  
  <p>Error   12  Name 'a' is not declared.   C:\Users\Documents\Visual Studio 2008\WebSites\vv_home\roeMgr.aspx.vb  51  46  C:\</p>
  
  <p>HERE is the VB code thus far.....</p>
  
  <pre><code>    Protected Sub MoveGridViewRows(ByVal sender As Object, ByVal e As EventArgs)
  
  
      Dim btnUp As Button = DirectCast(sender, Button)
      Dim row As GridViewRow = DirectCast(btnUp.NamingContainer, GridViewRow)
      ' Get all items except the one selected      
      Dim rows = GridView1.Rows.Cast(Of GridViewRow)().Where(Function(a) a IsNot row).ToList()
  
  
      Select Case btnUp.CommandName
          Case "Up"
              'If First Item, insert at end (rotating positions)              
              If row.RowIndex.Equals(0) Then
                  rows.Add(row)
              Else
                  rows.Insert(row.RowIndex - 1, row)
              End If
              Exit Select
          Case "Down"
              'If Last Item, insert at beginning (rotating positions)              
              If row.RowIndex.Equals(GridView1.Rows.Count - 1) Then
                  rows.Insert(0, row)
              Else
                  rows.Insert(row.RowIndex + 1, row)
              End If
              Exit Select
      End Select
      GridView1.DataSource = rows.[Select](a &gt;= New With { _
       .FirstName = DirectCast(a.FindControl("txtFirstName"), TextBox).Text, _
       .LastName = DirectCast(a.FindControl("txtLastName"), TextBox).Text _
      }).ToList()
      GridView1.DataBind()
  
  
  End Sub
  </code></pre>
  
  <p>thanks,</p>