static void Main()
        {
            CustomersCollection customersCollection = new CustomersCollection();

            //FindAll
            //List<Customer> matchingCustomers = customersCollection.FindAll(temp => temp.CustomerName.StartsWith("S"));

            //Sort
            CustomerComparer customerComparer = new CustomerComparer();

            customersCollection.Sort(customerComparer);

            foreach (Customer cst in customersCollection)
            {
                Console.WriteLine(cst.CustomerID + ", " + cst.CustomerName + ", " + cst.Age + ", " + cst.CustomerType);
            } //MoveNext


            //Contains - IEquatable
            Customer customerToSearch = new Customer()
            {
                CustomerID = 102, CustomerName = "Scott1"
            };

            //Console.WriteLine(customersCollection.Contains(customerToSearch)); //Output: True

            Console.ReadKey();
        }
Example #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="DataManager"/> class.
 /// </summary>
 private DataManager()
 {
     this.groups           = new List <Group>();
     this.comparer         = new GroupComparer();
     this.customers        = new List <Customer>();
     this.customerComparer = new CustomerComparer();
 }
Example #3
0
        public MainWindow()
        {
            InitializeComponent();
            DataContext = this;
            rand        = new Random();
            customers   = CustomerCollection.Create();

            ListView1 = new ListCollectionView(customers)
            {
                IsLiveFiltering = true,
                IsLiveSorting   = true,
                Filter          = (item) => item is Customer customer && customer.Balance < 250000,
                CustomSort      = new CustomerComparer()
            };

            ListView2 = new ListCollectionView(customers)
            {
                IsLiveFiltering = true,
                IsLiveSorting   = true,
                Filter          = (item) => item is Customer customer && customer.Balance >= 250000,
                CustomSort      = new CustomerComparer()
            };

            /*
             * If you use live sorting with SortDescriptions, you don't need to put the property names in LiveSortingProperties
             * If you use live sorting with CustomSort, you must put the property names in LiveSortingProperties
             *
             * Either way you go, the underlying data object (in this case, Customer) must implement INotifyPropertyChanged.
             */

            ListView1.LiveFilteringProperties.Add(nameof(Customer.Balance));
            ListView2.LiveFilteringProperties.Add(nameof(Customer.Balance));

#if CSORT
            ListView1.LiveSortingProperties.Add(nameof(Customer.Balance));
            ListView2.LiveSortingProperties.Add(nameof(Customer.Balance));
#else
            // CustomSort was set when creating ListView (above), but gets set to null internally when adding SortDescriptions
            ListView1.SortDescriptions.Add(new SortDescription(nameof(Customer.Balance), ListSortDirection.Ascending));
            ListView2.SortDescriptions.Add(new SortDescription(nameof(Customer.Balance), ListSortDirection.Ascending));
#endif
            timer = new DispatcherTimer
            {
                Interval = TimeSpan.FromMilliseconds(250),
            };
            timer.Tick += TimerTick;
        }