I have a code that should check a list of elements in an array and the resulting list should give me eliminating the repeating values. Here is my code
List <int> ProductListFinalized = new List<int>(ProductIdList);
for(int i = 0 ; i < ProductIdList.Count(); i++)
{
int ProductId = ProductIdList[i];
Res= !(ProductListFinalized.Contains(ProductId));
if(!(ProductListFinalized.Contains(ProductId)))
{
ProductListFinalized.Add(ProductId);
}
}
ProductIdListForCycleCount = ProductListFinalized.ToArray();
I am still finding the repeating values in the resulting Array. Whats is wrong with my code?
new List<int>(ProductIdList);, you certainly don't want thatProductListFinalized.Select(x => x.ProductId).Distinct();HashSet<int>