Finding Duplicate causing Performance Issue in Count

  • Thread starter Thread starter ID GO
  • Start date Start date
I

ID GO

Guest
private void CutData()
{
if (Collection.SelectedCells == null) return;
var sb = new StringBuilder();
var controlList = new List<string>();
foreach (var variable in Collection.SelectedCells)
{
controlList.Add(variable.Column.Header.ToString());
if (controlList.Count != controlList.Distinct().Count())
{
sb.AppendLine(null);
controlList.Clear();
controlList.Add(variable.Column.Header.ToString());
}
switch (variable.Column.Header.ToString())
{
case "Drug":
sb.Append(((Model)variable.Item).Drug).Append("\t");
((Model)variable.Item).Drug = "";
break;
case "Dosage":
sb.Append(((Model)variable.Item).Dosage).Append("\t");
((Model)variable.Item).Dosage = "";
break;
case "Patient":
sb.Append(((Model)variable.Item).Patient).Append("\t");
((Model)variable.Item).Patient = "";
break;
case "Date":
sb.Append(((Model)variable.Item).Date).Append("\t");
((Model)variable.Item).Date = "";
break;
}
}
Clipboard.SetText(sb.ToString(), TextDataFormat.Text);
sb.Clear();
}



Problem Statement :

controlList.Count != controlList.Distinct().Count()

This Line is Causing Performance Issue when I am Dealing with Lakh's of Data.

List of string contains not more then 8 items...Because I will get the Duplicate Value with in 8 items
After that I will clear the List

Need to Increase the Speed.



1306329.png

Continue reading...
 
Back
Top