To remove the duplicates values in list i used distinct but it is not working
ID Name Questions
1 OLAM "Produto prefer":"Algodão","Plantou algodão":"Sim"
2 OLAM "Produto prefer:"Feijão Buer","Plantou algodão":"Não"
3 OLAM "Produto prefer":"Buer","Plantou algodão":"Jao"
My code as follows
int columnindex = 43;
foreach (DataRow row in dtFarmerFarmReports.Rows)
{
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(row["farm_detailsdata"].ToString());
string str = string.Empty;
List<string> lst = new List<string>();
lst.AddRange(dict.Keys);
var distinctList = lst.Distinct().ToList();
foreach (var data in distinctList)
{
columnindex++;
worksheet.Cells[2, columnindex].Value = data;
}
}
When i run the above code output i get as follows
Produto prefer Plantou algodão Produto prefer Plantou algodão Produto prefer Plantou algodão
But i want the output as follows
Produto prefer Plantou algodão
i want to remove the duplicates.
for that i written a above code but it is not working.
please help me what changes i have to made in my above code to remove the duplicates
What I have tried:
To remove the duplicates values in list i used distinct but it is not working
ID Name Questions
1 OLAM "Produto prefer":"Algodão","Plantou algodão":"Sim"
2 OLAM "Produto prefer:"Feijão Buer","Plantou algodão":"Não"
3 OLAM "Produto prefer":"Buer","Plantou algodão":"Jao"
My code as follows
int columnindex = 43;
foreach (DataRow row in dtFarmerFarmReports.Rows)
{
var dict = JsonConvert.DeserializeObject<Dictionary<string, string>>(row["farm_detailsdata"].ToString());
string str = string.Empty;
List<string> lst = new List<string>();
lst.AddRange(dict.Keys);
var distinctList = lst.Distinct().ToList();
foreach (var data in distinctList)
{
columnindex++;
worksheet.Cells[2, columnindex].Value = data;
}
}
When i run the above code output i get as follows
Produto prefer Plantou algodão Produto prefer Plantou algodão Produto prefer Plantou algodão
But i want the output as follows
Produto prefer Plantou algodão
i want to remove the duplicates.
for that i written a above code but it is not working.
please help me what changes i have to made in my above code to remove the duplicates