[英]How do I calculate number of list of strings from listbox and multiply?
我在这里写了一段代码。 它循环过去。 我使用了一个if
语句来检查 Fizz 是否在 ListBox 中打印了 3 次。 如果有,我想要一个简单的乘以 3 的计算。然后,打印出 TextBox 中的值。
因此,Fizz 打印三遍,它将乘以我的 3,即等于 9。如何将 Listbox 中的字符串转换为 int 以便它可以计算 3 x 3 = 9,如果应该这样做的话。
string Output = "Fizz";
for (int a = 1; a <= 10; a++)
{
if (a == 3)
{
for (int b = 1; b <= 3; b++)
{
listBox4.Items.Add(Output);
int multiplyBy = 3;
//int numVal = Int32.Parse("3");
listBox4.Items.Count.ToString();
}
textBox1.Text = listBox4.Items.Count.ToString();
}
}
谢谢如果有人可以帮助我。
使用 Int32.Parse 或 Convert.ToInt32
请参阅 MSDN https://msdn.microsoft.com/en-us/library/bb397679.aspx
和 MSDN https://msdn.microsoft.com/en-us/library/system.int32.parse(v=vs.110).aspx
不确定你想要什么,但我会根据你写的内容尝试一下:
string output = "Fizz";
// Loop from 1 to 10 for no reason
for (int a = 1; a <= 10; a++)
{
// Add "Fizz" item to listbox 3 times if 'a' equals 3
if (a == 3)
{
for (int b = 1; b <= 3; b++)
{
listBox1.Items.Add(output);
}
// Multiply number of items in listBox with 3 for no reason and display it in textbox
textBox1.Text = (listBox1.Items.Count * 3).ToString();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.