Esempio n. 1
0
        public void RunDemo()
        {
            string[] bands = DemoCollections.GetBands();
            bool     all   = bands.All(b => b.Length > 2);

            Console.WriteLine(all);
        }
        public void RunDemo()
        {
            string[] bands = DemoCollections.GetBands();

            IEnumerable <string> orderedOne = bands.OrderBy(band => band.Length);

            foreach (string item in orderedOne)
            {
                //Console.WriteLine(item);
            }

            IEnumerable <string> orderedTwo = bands.OrderBy(band => band, new ConsonantNumberComparer());

            foreach (string item in orderedTwo)
            {
                //Console.WriteLine(item);
            }

            IEnumerable <string> orderedThree = bands.OrderBy(band => band, new ConsonantNumberComparer()).ThenBy(band => band);

            foreach (string item in orderedThree)
            {
                //Console.WriteLine(item);
            }

            IEnumerable <string> ordered = bands.OrderByDescending(band => band, new ConsonantNumberComparer()).ThenByDescending(band => band);

            foreach (string item in ordered)
            {
                Console.WriteLine(item);
            }
        }
        public void RunDemo()
        {
            string[] bands  = DemoCollections.GetBands();
            bool     exists = bands.Any();

            //bool exists = bands.Any(b => b.EndsWith("hkhkj"));
            Console.WriteLine(exists);
        }
Esempio n. 4
0
        public void RunDemo()
        {
            string[]             bands = DemoCollections.GetBands();
            IEnumerable <string> res   = bands.Skip(10);

            foreach (string item in res)
            {
                Console.WriteLine(item);
            }
        }
Esempio n. 5
0
        public void RunDemo()
        {
            string[]             bands         = DemoCollections.GetBands();
            IEnumerable <string> bandsReversed = bands.Reverse();

            foreach (string item in bandsReversed)
            {
                Console.WriteLine(item);
            }
        }
Esempio n. 6
0
        public void RunDemo()
        {
            string[]             bands         = DemoCollections.GetBands();
            IEnumerable <string> selectedItems = bands.Take(5).Concat(bands.Reverse().Take(5));

            foreach (string item in selectedItems)
            {
                Console.WriteLine(item);
            }
        }
Esempio n. 7
0
        public void RunSelectManyOperatorExample()
        {
            string[] bands = DemoCollections.GetBands();


            IEnumerable <char> characters = bands.SelectMany(b => b.ToArray());

            foreach (char item in characters)
            {
                Console.WriteLine(item);
            }
        }
Esempio n. 8
0
        public void RunDemo()
        {
            string[] bands    = DemoCollections.GetBands();
            string[] bandsTwo = DemoCollections.GetBands();
            bool     equal    = bands.SequenceEqual(bandsTwo);

            Console.WriteLine(equal);

            IEnumerable <Singer> singers    = DemoCollections.GetSingers();
            IEnumerable <Singer> singersTwo = DemoCollections.GetSingers();
            bool singersEqual = singers.SequenceEqual(singersTwo, new DefaultSingerComparer());

            Console.WriteLine(singersEqual);
        }
Esempio n. 9
0
        public void RunDemo()
        {
            string[]             bands = DemoCollections.GetBands();
            IEnumerable <string> res   = bands.SkipWhile(s => s.Length < 10);

            foreach (string item in res)
            {
                //Console.WriteLine(item);
            }

            IEnumerable <string> res2 = bands.SkipWhile((s, i) => s.Length < 10 && i < 10);

            foreach (string item in res2)
            {
                Console.WriteLine(item);
            }
        }
        public void RunDemo()
        {
            string[]             bands = DemoCollections.GetBands();
            IEnumerable <string> res   = bands.TakeWhile(b => b[0] != 'E');

            foreach (string s in res)
            {
                //Console.WriteLine(s);
            }

            IEnumerable <string> res2 = bands.TakeWhile((b, i) => b[0] != 'E' && i < 8);

            foreach (string s in res2)
            {
                Console.WriteLine(s);
            }
        }
Esempio n. 11
0
        public void RunTakeDemo()
        {
            string[] bands = DemoCollections.GetBands();

            IEnumerable <String> topItems = bands.Take(10);

            foreach (string item in topItems)
            {
                //Console.WriteLine(item);
            }

            var anonymous = bands.Take(10).Select(b => new { Name = b, Length = b.Length });

            foreach (var anon in anonymous)
            {
                Console.WriteLine("Band name: {0}, length: {1}", anon.Name, anon.Length);
            }
        }
Esempio n. 12
0
        public void RunDemo()
        {
            string[]             bands           = DemoCollections.GetBands();
            IEnumerable <string> bandsDuplicated = bands.Concat(bands);
            IEnumerable <string> uniqueBands     = bandsDuplicated.Distinct();

            foreach (String unique in uniqueBands)
            {
                Console.WriteLine(unique);
            }

            IEnumerable <Singer> singers           = DemoCollections.GetSingers();
            IEnumerable <Singer> singersDuplicates = singers.Concat(singers);
            IEnumerable <Singer> uniqueSingers     = singersDuplicates.Distinct(new DefaultSingerComparer());

            foreach (Singer singer in uniqueSingers)
            {
                Console.WriteLine(singer.Id);
            }
        }
Esempio n. 13
0
        public void RunSelectOperatorExample()
        {
            string[] bands = DemoCollections.GetBands();

            IEnumerable <int> lengths = bands.Select(b => b.Length);

            foreach (int l in lengths)
            {
                Console.WriteLine(l);
            }

            var customObjects = bands.Select(b => new { Name = b, Length = b.Length });

            foreach (var item in customObjects)
            {
                Console.WriteLine("Band name: {0}, length: {1}", item.Name, item.Length);
            }

            IEnumerable <Band> bandListSimple = bands.Select(b => new Band()
            {
                AllCapitals = b.ToUpper(), Name = b, NameLength = b.Length
            });

            foreach (Band band in bandListSimple)
            {
                Console.WriteLine(string.Concat(band.Name, ", ", band.NameLength, ", ", band.AllCapitals));
            }

            IEnumerable <Band> bandList = bands.Select((b, i) => new Band()
            {
                AllCapitals = b.ToUpper(), BandIndex = i + 1, Name = b, NameLength = b.Length
            });

            foreach (Band band in bandList)
            {
                Console.WriteLine(string.Concat(band.BandIndex, ": ", band.Name, ", ", band.NameLength, ", ", band.AllCapitals));
            }
        }