Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Program
- {
- static void Main(string[] args)
- {
- Console.WriteLine("Hello World!");
- List<Shoe> shoeCloset = new List<Shoe>();
- shoeCloset.Add(new Shoe() { Size = 19, Style = Style.Clogs, Color = "czarny" });
- shoeCloset.Add(new Shoe() { Size = 18, Style = Style.Sneakers, Color = "zielony" });
- shoeCloset.Add(new Shoe() { Size = 15, Style = Style.Wingtips, Color = "czerwony" });
- shoeCloset.Add(new Shoe() { Size = 114, Style = Style.Clogs, Color = "niebieski" });
- shoeCloset.Add(new Shoe() { Size = 11, Style = Style.Sneakers, Color = "czarny" });
- shoeCloset.Add(new Shoe() { Size = 12, Style = Style.Wingtips, Color = "czerwony" });
- int numberOfShoes = shoeCloset.Count;
- ComparerBySize comparerShoeBySize = new ComparerBySize();
- shoeCloset.Sort(comparerShoeBySize);
- comparerShoeBySize.PrintShoe(shoeCloset);
- foreach (Shoe shoe in shoeCloset)
- {
- Console.WriteLine(shoe.Size.ToString(), shoe.Color, shoe.Style.ToString());
- }
- shoeCloset.Sort();
- foreach (Shoe shoe in shoeCloset)
- {
- Console.WriteLine(shoe.Size.ToString(), shoe.Color, shoe.Style.ToString());
- }
- Console.ReadLine();
- }
- }
- public enum Style
- {
- Sneakers,
- Clogs,
- Wingtips,
- Loafers
- }
- public class Shoe : IComparable<Shoe>
- {
- public string Color { get; set; }
- public Style Style { get; set; }
- public int Size;
- public int CompareTo(Shoe other)
- {
- if (this.Size > other.Size)
- return 1;
- else if (this.Size < other.Size)
- return -1;
- else return 0;
- }
- }
- public class ComparerBySize : IComparer<Shoe>
- {
- public int Compare(Shoe x, Shoe y)
- {
- if (x.Size < y.Size) return 1;
- else if (x.Size > y.Size) return -1;
- else return 0;
- }
- public void PrintShoe(List<Shoe> shoes)
- {
- foreach (Shoe item in shoes)
- {
- Console.WriteLine(item.Size.ToString() + "-centymetorwy but" + item.Style.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement