繁体   English   中英

如何从列表框中计算字符串列表的数量并相乘?

[英]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();            
    }
}

谢谢如果有人可以帮助我。

不确定你想要什么,但我会根据你写的内容尝试一下:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM