windows phone 8 -在c#中访问名字时使用int
本文关键字:int 访问 phone windows | 更新日期: 2023-09-27 17:53:19
我目前正在使用c#构建一个windows phone 8应用程序,我想知道我如何才能实现这一点:
for (int i = 1; i <= 18; i++)
{
_(i)Score.Text = "whatever here";
}
在运行时应该是这样的:
_1Score.Text = "whatever here";
_2Score.Text = "whatever here";
_3Score.Text = "whatever here";
etc.
我怎么能做到这一点,只是把_(i)Score
不工作。
编辑:我所做的是做一个记分卡应用程序,其中有一个表的概述。我将它们分别命名为1score, 2Score, 3Score等,我只是想更新它们所说的内容。它们都是文本框,我只是替换里面的文本。
请帮助。由于
这是实现你正在做的事情的最直接的方法:
var name = string.Format("_{0}Score", i);
this.Controls[name].Text = "...";
了解类型(基于@sa_ddam213的注释):
foreach(var textBox in Children.OfType<TextBox>().Where(txt => txt.Name.EndsWith("Score")))
{
textBox.Text = "...";
}