@MiPakTeh, based on my test, I could get your wanted result. I guess that maybe you changed the code somewhere.
Here is a small completed code example you could refer to.
public partial class Form1 : Form
{
List<string> Data1 = new List<string>();
List<string> Data2 = new List<string>();
List<ItemInfo> Items = new List<ItemInfo>();
public static List<string> list = new List<string>();
int Lines = 0;
int Lines_a = 0;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
foreach (var item in Data1)
{
++Lines_a;
listBox2.Items.Add(item + " =>" + Lines_a);
var Items = new List<ItemInfo>();
int min = int.MaxValue;
int max = int.MinValue;
for (int j = 0; j <= 9; j++)
{
String Number_ = j.ToString();
int NumberCount_ = item.ToString().Replace(",", "").ToCharArray().Count(c => c.ToString() == Number_);
listBox2.Items.Add(Number_ + " = " + NumberCount_);
Items.Add(new ItemInfo() { Index = Convert.ToInt32(Number_.ToString()), Value = NumberCount_ });
}
foreach (ItemInfo ITM in Items)
{
if (ITM.Value < min)
{
min = ITM.Value;
}
if (ITM.Value > max)
{
max = ITM.Value;
}
}
string List = "";
string List_ = "";
string List_1 = "";
foreach (ItemInfo ITM in Items)
{
if (ITM.Value == min)
{
List += "Min = " + min.ToString() + " , " + "ItemMin = " + ITM.Index.ToString() + " " + " || ";
}
if (ITM.Value == max)
{
if(!List_.Contains("ItemMax"))
{
List_ += "Max = " + max.ToString() + " , " + "ItemMax = " + ITM.Index.ToString() + " => ";
}
}
}
listBox2.Items.Add(List + " " + List_+" "+Lines_a);
Data2.Add(List + " " + List_ + " " + List_1);
}
}
private void button2_Click(object sender, EventArgs e)
{
var duplicates = Data2.Select((t, i) => new { Index = i + 1, Text = t }).GroupBy(g => g.Text).Where(g => g.Count() >= 1).ToList();
foreach (var item in duplicates)
{
var result = item.Select(i => i.Index + " " + i.Text).ToArray();
string text = string.Join(" ", result);
listBox3.Items.Add(text);
}
}
private void Form1_Load(object sender, EventArgs e)
{
foreach (var s in File.ReadLines(@"E:\test.txt")
.Select(s => s.Split(new[] { ',' }, 3)[2]))
{
listBox1.Items.Add(++Lines + " " + s);
Data1.Add(s);
}
}
}
public partial class ItemInfo
{
public int Index;
public int Value;
public override string ToString()
{
return Index.ToString() + " => " + Value.ToString();
}
}
Tested result:
Best Regards,
Jack
If the answer is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.