using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[] args) { ObservableCollection<MyItems> _list1 = new ObservableCollection<MyItems>(); _list1.Add(new MyItems("A001", "Deodorant", 10)); _list1.Add(new MyItems("A0ZZ", "Hairspray", 20)); _list1.Add(new MyItems("A002", "Toothpaste", 30)); _list1.Add(new MyItems("0001", "Advacado", 0)); ObservableCollection<MyItems> _list2 = new ObservableCollection<MyItems>(); _list2.Add(new MyItems("A001", "Deodorant", 10)); _list2.Add(new MyItems("A002", "Toothpaste", 30)); /* TODO: Develop logic that will add all items from _list1 that are not already present into _list2. Items should be added into specific * index positions according to the following rule: if DisplaySequence is not equal to zero, insert into the correct position according * to that value; if DisplaySequence is equal to zero insert alphabetically according to the ItemName. The below foreach statement should * output in the following order: * * 0001 - Advacado * A001 - Deodorant * A0ZZ - Hairspray * A002 - Toothpaste */ foreach (var i in _list2) { Console.WriteLine(i.ItemName + " - " + i.ItemDescription); } Console.WriteLine("Press any key to exit."); Console.ReadKey(); } } class MyItems { public MyItems(string _itemName, string _itemDescription, int _displaySequence) { ItemName = _itemName; ItemDescription = _itemDescription; DisplaySequence = _displaySequence; } public string ItemName { get; set; } public string ItemDescription { get; set; } public int DisplaySequence { get; set; } } }
Add
Insert
Contains
IndexOf
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)