简体   繁体   English

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

[英]How do I calculate number of list of strings from listbox and multiply?

I have written a code here.我在这里写了一段代码。 It loops through.它循环过去。 I have used an if statement to check if Fizz has printed three times in the ListBox.我使用了一个if语句来检查 Fizz 是否在 ListBox 中打印了 3 次。 If it has, I would like a simple calculation with multiplication of 3. Then, prints out the value in the TextBox.如果有,我想要一个简单的乘以 3 的计算。然后,打印出 TextBox 中的值。

So, Fizz prints three times it will multiply my 3 which equals 9. How do I convert the string in the Listbox to int so that it can calculate `3 x 3 = 9, if that's how it should be done.因此,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();            
    }
}

Thanks if anyone can help me.谢谢如果有人可以帮助我。

Not sure what you want, but I will give it a try based on what you wrote:不确定你想要什么,但我会根据你写的内容尝试一下:

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.

相关问题 如何将字符串的observableCollection绑定到listBox - How do I Bind observableCollection of strings to a listBox 如何将ListBox绑定到XML文件中的对象列表? - How do I bind a ListBox to a list of objects from an XML file? 如何单击一个按钮,该按钮将从ListBox中删除一个项目,而该列表中包含C#中ListBox的信息? - How do I click a button that will remove an item from a ListBox and the List that holds the information for the ListBox in C#? 如何在列表框中获取 object 的列表? - How do i get a list of object in a Listbox? 如何用字符串数组填充“ asp:ListBox”? - How do I populate a 'asp:ListBox' with an array of strings? 如何在 2 个列表框和 output 之间相乘到另一个列表框 - How do you multiply between 2 listboxes and output to another listbox 如何限制列表框中要添加的项目数 - How do I limit the number of items to be added in listbox 如何将列表框的行/索引限制为指定的数字? - How do I limit the rows/indexes of a Listbox to a specified number? 如何获取列表框中所选项目的编号(C#) - How do I get the number of the item selected in a listbox (C#) 如何在没有选择和选择的情况下将整个列表数据从列表框中传递给控制器​​? - How do I pass a whole list data from a listbox without & with selection to controller?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM