簡體   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