Пример #1
0
    public static void Main()
    {
        var products = new FirstLastList <Product>();

        products.Add(new Product(0.50m, "coffee"));
        products.Add(new Product(1.20m, "mint drops"));
        products.Add(new Product(1.20m, "beer"));
        products.Add(new Product(0.35m, "candy"));
        products.Add(new Product(1.20m, "cola"));

        Console.WriteLine("========================= Count");
        Console.WriteLine(products.Count);
        Console.WriteLine(string.Join(Environment.NewLine, products.First(products.Count)));
        Console.WriteLine("========================= First");
        Console.WriteLine(string.Join(Environment.NewLine, products.First(count)));
        Console.WriteLine("========================= Last");
        Console.WriteLine(string.Join(Environment.NewLine, products.Last(count)));
        Console.WriteLine("========================= Min");
        Console.WriteLine(string.Join(Environment.NewLine, products.Min(count)));
        Console.WriteLine("========================= Max");
        Console.WriteLine(string.Join(Environment.NewLine, products.Max(count)));
        Console.WriteLine("========================= Remove All @ Price 1.20");
        var product = new Product(1.20m);

        Console.WriteLine($"Removed {products.RemoveAll(product)}");
        Console.WriteLine(string.Join(Environment.NewLine, products.First(products.Count)));
        Console.WriteLine("========================= Clear");
        products.Clear();
        Console.WriteLine(products.Count);
    }
    private static void Main()
    {
        var items = new FirstLastList<string>();
        items.Add("zero");
        Console.WriteLine("Count: {0}", items.Count);
        Console.WriteLine("First: {0}", items.First(1).FirstOrDefault());
        Console.WriteLine("Last: {0}", items.Last(1).FirstOrDefault());
        Console.WriteLine("Min: {0}", items.Min(1).FirstOrDefault());
        Console.WriteLine("Max: {0}", items.Max(1).FirstOrDefault());

        items.Clear();

        items.Add("first");
        items.Add("second");
        items.Add("third");
        items.Add("fourth");
        Console.WriteLine("Count: {0}", items.Count);
        Console.WriteLine("First: {0}", items.First(1).FirstOrDefault());
        Console.WriteLine("Last: {0}", items.Last(1).FirstOrDefault());
        Console.WriteLine("Min: {0}", items.Min(1).FirstOrDefault());
        Console.WriteLine("Max: {0}", items.Max(1).FirstOrDefault());

        Console.WriteLine("RemoveAll('first'): {0}",
            items.RemoveAll("first"));
        Console.WriteLine("RemoveAll('fourth'): {0}",
            items.RemoveAll("fourth"));
        Console.WriteLine("RemoveAll('first'): {0}",
            items.RemoveAll("first"));
        Console.WriteLine("Count: {0}", items.Count);
        Console.WriteLine("First: {0}", items.First(1).FirstOrDefault());
        Console.WriteLine("Last: {0}", items.Last(1).FirstOrDefault());
        Console.WriteLine("Min: {0}", items.Min(1).FirstOrDefault());
        Console.WriteLine("Max: {0}", items.Max(1).FirstOrDefault());
    }
Пример #3
0
    static void Main()
    {
        var items = new FirstLastList <string>();

        items.Add("zero");
        Console.WriteLine("Count: {0}", items.Count);
        Console.WriteLine("First: {0}", items.First(1).FirstOrDefault());
        Console.WriteLine("Last: {0}", items.Last(1).FirstOrDefault());
        Console.WriteLine("Min: {0}", items.Min(1).FirstOrDefault());
        Console.WriteLine("Max: {0}", items.Max(1).FirstOrDefault());

        items.Clear();

        items.Add("first");
        items.Add("second");
        items.Add("third");
        items.Add("fourth");
        Console.WriteLine("Count: {0}", items.Count);
        Console.WriteLine("First: {0}", items.First(1).FirstOrDefault());
        Console.WriteLine("Last: {0}", items.Last(1).FirstOrDefault());
        Console.WriteLine("Min: {0}", items.Min(1).FirstOrDefault());
        Console.WriteLine("Max: {0}", items.Max(1).FirstOrDefault());

        Console.WriteLine("RemoveAll('first'): {0}",
                          items.RemoveAll("first"));
        Console.WriteLine("RemoveAll('fourth'): {0}",
                          items.RemoveAll("fourth"));
        Console.WriteLine("RemoveAll('first'): {0}",
                          items.RemoveAll("first"));
        Console.WriteLine("Count: {0}", items.Count);
        Console.WriteLine("First: {0}", items.First(1).FirstOrDefault());
        Console.WriteLine("Last: {0}", items.Last(1).FirstOrDefault());
        Console.WriteLine("Min: {0}", items.Min(1).FirstOrDefault());
        Console.WriteLine("Max: {0}", items.Max(1).FirstOrDefault());
    }
Пример #4
0
    static void Main(string[] args)
    {
        FirstLastList <int> list = new FirstLastList <int>();

        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        Console.WriteLine();
    }
Пример #5
0
    static void Main(string[] args)
    {
        var items = new FirstLastList <int>();

        items.Add(5);
        items.Add(10);
        items.Add(-2);

        // Act
        items.Last(2).ToList().ForEach(x => Console.Write(x + " "));
    }
Пример #6
0
    static void Main(string[] args)
    {
        FirstLastList <Product> items = new FirstLastList <Product>();

        items.Add(new Product(0.50m, "coffee"));
        items.Add(new Product(1.20m, "mint drops"));
        items.Add(new Product(1.20m, "beer"));
        items.Add(new Product(0.50m, "candy"));
        items.Add(new Product(1.20m, "cola"));


        var returnedItems = items.Min(4).Select(p => p.Title).ToList();


        //var expectedItems = new string[] {
        //    "coffee", "candy", "mint drops", "beer" };
        //CollectionAssert.AreEqual(expectedItems, returnedItems);
    }
Пример #7
0
    static void Main(string[] args)
    {
        FirstLastList <int> list = new FirstLastList <int>();

        list.Add(1);
        list.Add(2);
        list.Add(3);
        list.Add(4);
        Console.WriteLine();

        List <string> words = new List <string>()
        {
            "zz", "coffee", "milk",
        };
        List <string> newList = words.OrderBy(x => x).ToList();

        Console.WriteLine(string.Join(" ", newList));
    }
Пример #8
0
    static void Main(string[] args)
    {
        FirstLastList <int> list = new FirstLastList <int>();

        list.Add(5);
        list.Add(6);
        list.Add(1);
        list.Add(3);
        list.Add(3);
        list.Add(8);
        list.Add(3);

        Console.WriteLine(list.RemoveAll(150));
        Console.WriteLine(list.RemoveAll(3));
    }
Пример #9
0
    static void Main(string[] args)
    {
        FirstLastList <int> list = new FirstLastList <int>();

        list.Add(3);
        list.Add(1);
        list.Add(4);
        list.Add(4);
        list.Add(2);
        list.Add(-3);
        Console.WriteLine(string.Join(" - ", list.Max(5)));
    }
Пример #10
0
    static void Main(string[] args)
    {
        FirstLastList <int> list = new FirstLastList <int>();

        list.Add(1);
        list.Add(2);
        list.Add(2);
        list.Add(2);
        list.Add(2);
        list.Add(3);
        list.Add(4);

        foreach (var biggestItem in list.Max(3))
        {
            Console.WriteLine(biggestItem);
        }
    }
Пример #11
0
    static void Main(string[] args)
    {
        FirstLastList <int> list = new FirstLastList <int>();

        //list.Add(1);
        //list.Add(2);
        //list.Add(3);
        //list.Add(4);
        //Console.WriteLine();

        list.Add(200);
        list.Add(120);
        list.Add(220);
        list.Add(220);
        list.Add(10);
        list.Add(6);
        list.Add(1);

        list.RemoveAll(220);
        var result = list.Max(4);

        Console.WriteLine();
    }