Wednesday, November 16, 2016

Remove items from List

using System.Collections.Generic;
using System.Diagnostics;
using System.Windows;

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            List<Dealer> myList = new List<Dealer> {
                new Dealer() {Text = "Dealer A", IsSelected = false },
                new Dealer() {Text = "Dealer B", IsSelected = true },
                new Dealer() {Text = "Dealer C", IsSelected = false },
            };

            myList.RemoveAll(x => x.IsSelected == true);

            foreach (Dealer d in myList)
            {
                Debug.WriteLine("ITem: " + d.Text);
            }
        }
    }

    class Dealer
    {
        public string Text { get; set; }
        public bool IsSelected { get; set; }
    }
}

No comments: