0

Hi
I have a textBox that get integer from user.
I want a button programming that for example if i give the textBox these numbers (5 8 16 16 5 1 0 5) with button_Click show "There is three 5 and two 16".

I am using WPF(C#). Thanks for your responses.

mehdi
  • 1

1 Answers1

0

public List refrence;

    public MainWindow()
    {
        InitializeComponent();
        refrence = new List<int>();
    }


    private void buttonAdd_Click(object sender, RoutedEventArgs e)
    {
        refrence.Add(int.Parse(textBox.Text));
        textBox.Clear();
        listBox.Items.Clear();
    }
    private void buttonSearch_Click(object sender, RoutedEventArgs e)
    {
        List<int> q = new List<int>();
        int[] query = refrence.ToArray();
        for (int i = 0; i < query.Length; i++)
            for (int j = i + 1; j < query.Length; j++)
            {
                if (query[i] == query[j])
                {
                    q.Add(query[j]);
                    var qwe = q.Distinct();
                    foreach(var item in qwe)
                    listBox.Items.Add(item);
                }
            }
    }</i>

But it shows 5 5 5 16 5 16 in listBox

mehdi
  • 1