如何循环使用C#的名字 [英] How To loop the names in C#

查看:110
本文介绍了如何循环使用C#的名字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有10个文本框即TB1,TB2,TB3,TB4等..到TB10

I have 10 text boxes namely TB1, TB2, TB3, TB4 and so on.. to TB10

我想将它们存储到一个名为toBeStored一个字符串值

I want to store them into a single string value named toBeStored.

现在我米做手工的方式

String toBeStored=null;
tobeStored=TB1.text.toString();
tobeStored+=TB2.text.toString();



等..

and so on..

我想使一个for循环,并将它们添加

I want to make a for loop and add them

这样的事情。

for(int i=1;i<11;i++)
{
      toBeStored+=TB+i+.text.ToString()+"  ";
}



我知道这是不对的..任何事情作出正确的?

I know that is wrong.. anything to make it right?

推荐答案

没有。因为你定义的文本框为变量,目前根本没有定义的枚举。

No. Because you defined the text boxes as variables there simply is no enumerator defined.

您可以定义自己的枚举。在这是

You could define your own enumerator. In the simpliest case that is as simple as

TextBox boxes [] = new TextBox [] { TB1, TB2, TB3....}

foreach (TextBox box in boxes) {
}

这篇关于如何循环使用C#的名字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆