0

我目前正在使用 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不起作用。

编辑:我正在做的是制作一个有表格概览的记分卡应用程序。我将每一个命名为 1Socre、2Score、3Score 等,我只想更新他们所说的内容。它们都是文本框,我只是替换里面的文本。

请帮忙。谢谢

4

1 回答 1

5

这是实现您正在做的事情的最直接方式:

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 = "...";
}
于 2013-01-14T22:36:46.723 回答