I have a list of objects that returned from the DB, I am using linq to compare specific value with property in the list , and if the value found in the list with percent 80% or above, then return repeated item else return the object.
I write code but it's return repeated if the value as same as property.
List<CatalogDTO> lst=new List<CatalogDTO>();
var catalogname="Iphone s";
List<CatalogDTO> lstCatalogs= new List<CatalogDTO>();
lstCatalogs.Add(new CatalogDTO{ Id=1,CatalogName ="Iphone red"});
lstCatalogs.Add(new CatalogDTO{ Id=2,CatalogName ="Iphone green"});
lstCatalogs.Add(new CatalogDTO{ Id=3,CatalogName ="iphone x"});
lstCatalogs.Add(new CatalogDTO{ Id=4,CenterNameAr="iphone xs"});
var catalog = lstCatalogs.where(x=> x.CatalogName == catalogname).FirstOrDefault();
if(catalog !=null){
return "Repeated Catalog";
}
else{
lst.Add(catalog);
}
The code above must return objects with Ids 3 and 4 because the similarity about 80% or more (means the percent of characters similarity as all words in the string except one for example ).