public void Exercise() { var myCollection = new PrettyLameCollection <Thingamabob> { new Thingamabob { Doohickey = 5, Whatchamacallit = "Chris" }, new Thingamabob { Doohickey = 1, Whatchamacallit = "Kelly" }, new Thingamabob { Doohickey = 4, Whatchamacallit = "Scott" }, new Thingamabob { Doohickey = 8, Whatchamacallit = "Ron" }, new Thingamabob { Doohickey = 2, Whatchamacallit = "Eric" } }; myCollection.Sort(); // TODO: Use the same Sort method that you wrote in Exercise 1 to sort the collection of Thing-a-ma-bobs by their Doohickeys in descending order. Use a lambda expression to satisfy the delegate. CollectionAssert.AreEqual(new[] { 8, 5, 4, 2, 1 }, myCollection.Select(t => t.Doohickey)); }
public void Exercise() { var myCollection = new PrettyLameCollection <Thingamabob> { new Thingamabob { Doohickey = 5, Whatchamacallit = "Chris" }, new Thingamabob { Doohickey = 1, Whatchamacallit = "Kelly" }, new Thingamabob { Doohickey = 4, Whatchamacallit = "Scott" }, new Thingamabob { Doohickey = 8, Whatchamacallit = "Ron" }, new Thingamabob { Doohickey = 2, Whatchamacallit = "Eric" } }; myCollection.Sort(); // TODO: Add an overload the Sort method on PrettyLameCollection that takes in the appropriate Func<> or Action<> and sort the collection of Thing-a-ma-bobs by their Doohickeys in descending order. CollectionAssert.AreEqual(new[] { 8, 5, 4, 2, 1 }, myCollection.Select(t => t.Doohickey)); }
public void Exercise() { var myCollection = new PrettyLameCollection<int> {5, 1, 4, 8, 2}; myCollection.Sort(CompareDescending); // TODO: Sort the collection in descending order. Try to add a delegate to PrettyLameCollection that is accepted as a parameter to an overload of the Sort method. Use a Named Method to satisfy the delegate. CollectionAssert.AreEqual(new[] { 8, 5, 4, 2, 1 }, myCollection); }
public void sorts_integers() { var myCollection = new PrettyLameCollection <int>(); myCollection.Add(5, 1, 4, 8, 2); myCollection.Sort(); CollectionAssert.AreEqual(new[] { 1, 2, 4, 5, 8 }, myCollection); }
public void sorts_string() { var myCollection = new PrettyLameCollection <string>(); myCollection.Add("Chris", "Kelly", "Scott", "Ron", "Eric"); myCollection.Sort(); CollectionAssert.AreEqual(new[] { "Chris", "Eric", "Kelly", "Ron", "Scott" }, myCollection); }
public void Exercise() { var myCollection = new PrettyLameCollection <int> { 5, 1, 4, 8, 2 }; myCollection.Sort(); // TODO: Sort the collection in descending order. Try to add a delegate to PrettyLameCollection that is accepted as a parameter to an overload of the Sort method. Use a Named Method to satisfy the delegate. CollectionAssert.AreEqual(new[] { 8, 5, 4, 2, 1 }, myCollection); }
public void Exercise() { var myCollection = new PrettyLameCollection<Thingamabob> { new Thingamabob {Doohickey = 5, Whatchamacallit = "Chris"}, new Thingamabob {Doohickey = 1, Whatchamacallit = "Kelly"}, new Thingamabob {Doohickey = 4, Whatchamacallit = "Scott"}, new Thingamabob {Doohickey = 8, Whatchamacallit = "Ron"}, new Thingamabob {Doohickey = 2, Whatchamacallit = "Eric"} }; myCollection.Sort(); // TODO: Use the same Sort method that you wrote in Exercise 1 to sort the collection of Thing-a-ma-bobs by their Doohickeys in descending order. Use a lambda expression to satisfy the delegate. CollectionAssert.AreEqual(new[] { 8, 5, 4, 2, 1 }, myCollection.Select(t => t.Doohickey)); }
public void Exercise() { var myCollection = new PrettyLameCollection<Thingamabob> { new Thingamabob {Doohickey = 5, Whatchamacallit = "Chris"}, new Thingamabob {Doohickey = 1, Whatchamacallit = "Kelly"}, new Thingamabob {Doohickey = 4, Whatchamacallit = "Scott"}, new Thingamabob {Doohickey = 8, Whatchamacallit = "Ron"}, new Thingamabob {Doohickey = 2, Whatchamacallit = "Eric"} }; myCollection.Sort(); // TODO: Add an overload the Sort method on PrettyLameCollection that takes in the appropriate Func<> or Action<> and sort the collection of Thing-a-ma-bobs by their Doohickeys in descending order. CollectionAssert.AreEqual(new[] { 8, 5, 4, 2, 1 }, myCollection.Select(t => t.Doohickey)); }
public void Exercise() { var myCollection = new PrettyLameCollection<Thingamabob> { new Thingamabob {Doohickey = 5, Whatchamacallit = "Chris"}, new Thingamabob {Doohickey = 1, Whatchamacallit = "Kelly"}, new Thingamabob {Doohickey = 4, Whatchamacallit = "Scott"}, new Thingamabob {Doohickey = 8, Whatchamacallit = "Ron"}, new Thingamabob {Doohickey = 2, Whatchamacallit = "Eric"} }; // TODO: Use the same Sort method that you wrote in Exercise 1 to sort the collection of Thing-a-ma-bobs by their Doohickeys in descending order. Use an anonymous method to satisfy the delegate. myCollection.Sort(delegate(Thingamabob left, Thingamabob right) { return Comparer<int>.Default.Compare(right.Doohickey, left.Doohickey); }); CollectionAssert.AreEqual(new[] {8, 5, 4, 2, 1}, myCollection.Select(t => t.Doohickey)); }