Duplicates in list

Eduardo Gomez 3,416 Reputation points
2022-07-25T21:51:51.673+00:00

For some reason, I get duplicate data, and I know that every city name I get in return has a different name.

224582-image.png

code https://github.com/eduardoagr/Travel

Windows Presentation Foundation
Windows Presentation Foundation
A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
2,678 questions
{count} votes

Accepted answer
  1. Hui Liu-MSFT 40,661 Reputation points Microsoft Vendor
    2022-07-28T08:00:47.127+00:00

    Hi,@Eduardo Gomez . You could refer to the code as follows.

      private async void GetAirportList()  
        {  
            var temppList = await Services.GetAirportsAsync();  
      
            //var tempObservable = new ObservableCollection<Airport>();  
            var tempObservable1 = new ObservableCollection<Airport>();  
            //foreach (var item in temppList!)  
            //{  
      
            //    if (!tempObservable.Contains(item))  
            //    {  
                      
            //        tempObservable.Add(item);  
            //    }  
                 
            //}  
            var newItems = temppList.Where(x => !tempObservable1.Any(y => x.city == y.city));  
            foreach (var item in newItems!)  
            {  
      
                if (!tempObservable1.Contains(item))  
                {  
      
                    tempObservable1.Add(item);  
                }  
      
            }  
      
            //AirportsList = tempObservable;  
            AirportsList = tempObservable1;  
             
        }  
    

    The result:
    225675-image.png


    If the response is helpful, please click "Accept Answer" and upvote it.
    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.


0 additional answers

Sort by: Most helpful