2017-12-18 242 views
-4

有人可以幫助我的等價代碼爲C#TypeOf運算和CTYPE代碼等同於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

在線轉換器是如何讓你失望? – Plutonix

回答

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

我得到一個錯誤:無法將類型'字符串'轉換爲'System.Windows.Forms.TextBox' – user3916571

+0

嘗試'((TextBox)ctrl).Text = string.Empty;'改爲。 –

+0

對於那個錯誤感到抱歉 –