Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
523 views
in Technique[技术] by (71.8m points)

c# - How to set FIFO and palindrome compare?

I have this windows application

enter image description here

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();

    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...