问题
I have this windows application
1.- So, first when I Add a number it added to listbox1 but not to list 2. I need to be add ed to listo 2 to
2.- I need the numbers be added separately... For example if I add number 202, it split on 2 after 0 after 2
3.- I need add button for FIFO, but I don't know how can I program it.
4.-Finally compare one by one it with listbox1 with listbox2 with polindrome method, and if its palindrome show message box, say "they are polindrome", if not, say "number it's not palindrome.
private void button1_Click(object sender, EventArgs e)
{
int newvalue;
if (int.TryParse(textBox1.Text, out newvalue))
{
numeros.Add(newvalue);
listBox1.Items.Add(textBox1.Text);
}
else
MessageBox.Show("insert a number");
textBox1.Clear();
textBox1.Focus();
}
回答1:
For dealing with this problem you should keep your main data in memory (List<int>
) and manipulate them using different methods and show the result in the listboxes.
Separating your digits can be done this way :
List<int> SeparateDigits(int n)
{
var result = new List<int>();
while(n>0)
{
result.Add(n % 10);
n /= 10;
}
return result;
}
After calling this method you can add the list data to both your listboxes if it's what you want.
(sorry for being late)
Good luck.
来源:https://stackoverflow.com/questions/32149543/how-to-set-fifo-and-palindrome-compare