I have a search code for just the number of identical numbers in active textboxes at the press of a button and outputting this amount in label2
: C #
private void button1_Click(object sender, EventArgs e) { foreach (TextBox tb in Controls.OfType<TextBox>().Where(x => x.Enabled == true)) { label2.Text = Controls.OfType<TextBox>().SelectMany(x => x.Text.Split(" ;:,.-".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)).GroupBy(x => x).Count(x => x.Count() > 1).ToString(); } }
Tell me how to remake this code so that it doesn’t compare all active textboxes at once, but each with the other, for example, the first with the second, the first with the third, and so on, then returns to the second and compares it with the following, and so Further. This is the first. The second is that after the textboxes are compared with each other, the code displays the minimum number of identical numbers in the label text (even wherever), even 0
, that is, even if there are no matches at all. And after all this, I would like to somehow reveal in which textboxes a minimum of duplicate numbers was found, for example, to change their background colors ( BackColor
) for others.
A little explanation to all of this. In code, tb
is an array of several text boxes. In each box, all numbers are different and are not repeated, they are entered by the user, not randomly, and separated by spaces. And for clarity, I will give a simple example with three textboxes. In the first there are numbers 10 15 20
, in the second 10 11 25
, in the third there are 30 11 25
. Here it is clear that the first has one coincidence with the second, the second has two coincidences with the third, and the first with the third does not. As a result, min. The number of identical numbers is 0
, and this number is inserted into the text of the label, while the first and third text boxes change their background color.
Yes, and also, if it is not difficult, how can I do that by pressing another button to compare text boxes, not everyone with each, but only the first with all the others? For example, if the textbox 3, then compare the first with the second and with the third, and the second with the third is not necessary. Well, again, after all this, bring out the minimum and change the color of the backgrounds. Thanks a lot in advance.
посчитать количество чисел, присутсующих во всех массивах сразу
. - pavel