相当于通过变量名来指控制?

Cam*_*llo 2 c# vb.net controls winforms

在VB中,我可以循环控制,或通过将变量连接到字符串来引用控件.就像是:

Dim I as integer
I = 1
Me["Textbox" & I].Text = "Some text"
Run Code Online (Sandbox Code Playgroud)

最后一个陈述的C#等价物是什么?

Sys*_*gon 6

您可以通过控件的名称访问该控件:

Me.Controls("TextBox" & I).Text = "Some text"
Run Code Online (Sandbox Code Playgroud)

在C#中也一样:

this.Controls["TextBox" + I].Text = "Some text";
Run Code Online (Sandbox Code Playgroud)