【发布时间】:2015-10-22 14:36:29
【问题描述】:
string[] names = { "Abby", "Bill", "Connie", "David", "Eddy" };
private void clearButton_Click(object sender, EventArgs e)
{
//Clear the array labels
array1Label.Text = "";
array2Label.Text = "";
}
private void passArrayButton_Click(object sender, EventArgs e)
{
//Demo how to pass an array
//Which really means passing the reference vairable to the array.
//Create an array
int[] array1 = {10, 20, 30, 40, 50};
//Pass array1 to a method to double and dsiplay the array
DoubleArray(array1);
}
private void DoubleArray(int[] theArray1)
{
string output = "";
for (int x = 0; x < theArray1.Length; x++)
{
theArray1[x] = theArray1[x] * 2;
}
//display the array
foreach(int element in theArray1)
{
output = output + element + "\n";
}
array1Label.Text = output;
}
private void showNameButton_Click(object sender, EventArgs e)
{
string[] names = { "Abby", "Bill", "Connie", "David", "Eddy" };
}
}
对如何使用顺序搜索能够将“David”输出到标签上深感困惑,请帮忙。这是我的整个程序,第一部分只是将所有数字相乘。请帮忙!没有外部输入,只需要通过“names”数组,挑出“David”,将文本输出到标签中即可。
【问题讨论】:
-
您在寻找
MyLabel.Text = names.Contains("David") ? "David" : "";吗? -
旁注:
array1Label.Text = String.Join(Environment.NewLine, theArray1);是您的 foreach 循环 的更好选择
标签: c# arrays sequential