How could I translate this code to C #?
If TypeOf (ctrl) Is GridView AndAlso Not DirectCast(ctrl, GridView).HeaderRow Is Nothing Then
Dim grid = DirectCast(ctrl, GridView)
For i = 0 To (grid.HeaderRow.Cells.Count - 1)
Dim _nombre As String = grid.HeaderRow.Cells(i).Text
Dim _ctrlP As ControlPantalla = ControlesPantalla.Where(Function(x) x.Nombre = _nombre).FirstOrDefault()
If Not _ctrlP Is Nothing Then
grid.HeaderRow.Cells(i).Text = _ctrlP.Texto
End If
Next
End If