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 it has, I would like a simple calculation with multiplication of 3. Then, prints out the value in the 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.
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.
Use Int32.Parse or Convert.ToInt32
See MSDN https://msdn.microsoft.com/en-us/library/bb397679.aspx
and MSDN https://msdn.microsoft.com/en-us/library/system.int32.parse(v=vs.110).aspx
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();
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.