@MiPakTeh , Sorry for the late response, based on my test, I make a code example for you to ahieve your requirement.
private void button1_Click(object sender, EventArgs e)
{
foreach (var item_ in Data1)
{
listBox2.Items.Add(item_);
var MyItems = new List<myItem>();
for (int j = 0; j <= 9; j++)
{
String Number_ = j.ToString();
int NumberCount_ = item_.Replace(",", "").ToCharArray().Count(c => c.ToString() == Number_);
MyItems.Add(new myItem() { Index = Convert.ToInt32(Number_.ToString()), Value = NumberCount_ });
}
foreach (myItem ITM in MyItems)
{
listBox2.Items.Add(ITM.Index + " = " + ITM.Value);
}
var Result = new Dictionary<string, int>();
foreach (myItem ITM in MyItems)
{
if (Result.ContainsKey(ITM.Value.ToString()))
{
Result[ITM.Value.ToString()] += 1;
}
else
{
Result.Add(ITM.Value.ToString(), 1);
}
}
string List = "";
foreach (KeyValuePair<string, int> KV in Result)
{
List += KV.Key + "=" + KV.Value.ToString();
List += ", ";
}
listBox2.Items.Add(List);
foreach (KeyValuePair<string, int> KV in Result)
{
string duvalue = string.Empty;
if (KV.Value>1)
{
var result = MyItems.Where(m => m.Value.ToString() == KV.Key);
foreach (var item in result)
{
duvalue += item.Index + "= " + item.Value+" ,";
}
listBox2.Items.Add(duvalue);
}
}
listBox2.Items.Add("==============================");
}
}
Result:
Hope the above code could help you.
Best Regards,
Jack
If the answer is the right solution, please click "Accept Answer" and upvote it.If you have extra questions about this answer, please click "Comment".
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.