Пример #1
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());
    }
    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
    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);
    }
Пример #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);
        var min = list.Min(3);

        Console.WriteLine(min.First());
    }
Пример #5
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);
    }