2017-12-18 3 views
-4

Kann mir jemand den entsprechenden Code in C#TypeOf und CType Code Äquivalent in C#

Public Sub ClearTextBox(ByVal root As Control) 
    For Each ctrl As Control In root.Controls 
     ClearTextBox(ctrl) 
     If TypeOf ctrl Is TextBox Then 
      CType(ctrl, TextBox).Text = String.Empty 
     End If 
    Next ctrl 
End Sub 
+5

helfen Wie haben die Online-Konverter Sie scheitern? – Plutonix

Antwort

3
public void ClearTextBox(Control root) 
{ 
    foreach (Control ctrl in root.Controls) 
    { 
     ClearTextBox(ctrl); 
     if (ctrl is TextBox) 
     { 
      ctrl.Text = string.Empty; 
     } 
    } 
} 
+0

Ich habe eine Fehlermeldung erhalten: Typ 'string' kann nicht in 'System.Windows.Forms.TextBox' konvertiert werden – user3916571

+0

Probieren Sie '((TextBox) ctrl) .Text = string.Empty;' statt. –

+0

Entschuldigung für diesen Fehler –