Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            var OneArtist = Artists.Select(Artist => new { name = Artist.RealName, age = Artist.Age, hometown = Artist.Hometown }).FirstOrDefault(artist => artist.hometown == "Mount Vernon");

            Console.WriteLine(OneArtist);
            //Who is the youngest artist in our collection of artists?

            //Display all artists with 'William' somewhere in their real name

            //Display the 3 oldest artist from Atlanta

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Console.WriteLine(Groups.Count);
        }
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            // List<Artist> ArtistsFromMV = Artists.Where(art => art.Hometown == "Mount Vernon").ToList();
            List <Artist> ArtistsFromMV = Artists.Where(art => art.Hometown.Contains("Mount Vernon")).ToList();

            //Who is the youngest artist in our collection of artists?
            Artist Youngest = Artists.OrderBy(art => art.Age).FirstOrDefault();

            //Display all artists with 'William' somewhere in their real name
            List <Artist> Williams = Artists.Where(art => art.RealName.Contains("William")).ToList();

            //Display the 3 oldest artist from Atlanta
            List <Artist> Oldest = Artists.Where(art => art.Hometown == "Atlanta").OrderByDescending(art => art.Age).Take(3).ToList();

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            var NotNYC = Groups.Join(Artists, g => g.Id, a => a.GroupId, (group, artist) => group).Where(group => group.Members.All(artist => artist.Hometown != "New York City")).ToList();

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            List <string> WuTangClan = Artists.Join(Groups, art => art.GroupId, gro => gro.Id, (artist, group) => artist).Where(artist => artist.Group.GroupName == "Wu-Tang Clan").Select(artist => artist.ArtistName).ToList();

            Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine(Groups.Count);
            Console.WriteLine(Artists.Count);
            Console.WriteLine("------------------------------------------------------------------------------------------------------------------------");
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist xxxx = Artists.FirstOrDefault(
                x => x.Hometown == "Mount Vernon");

            System.Console.WriteLine(xxxx.ArtistName);



            //Who is the youngest artist in our collection of artists?
            Artist youngest = Artists.FirstOrDefault(
                city => city.Age == Artists.Min(c => c.Age)
                );

            System.Console.WriteLine(youngest.ArtistName + " " + youngest.Age);



            //Display all artists with 'William' somewhere in their real name
            var William = Artists.Where(
                name => name.RealName.Contains("William"));

            foreach (var will in William)
            {
                System.Console.WriteLine(will.ArtistName);
            }



            //Display the 3 oldest artist from Atlanta

            var Atlanta = Artists.Where(
                name => name.Hometown.Contains("Atlanta"));
            var old = Atlanta.OrderByDescending(
                Age => Age.Age).Take(3);

            foreach (var ATL in old)
            {
                System.Console.WriteLine(ATL.ArtistName + " " + ATL.Age + " " + ATL.Hometown);
            }



            //(Optional) Display the Group Name of all groups that have members that are not from New York City



            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 4
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist mountVernon = Artists.FirstOrDefault(homeTown => homeTown.Hometown == "Mount Vernon");

            //Who is the youngest artist in our collection of artists?
            Artist bby = Artists.OrderBy(art => art.Age).FirstOrDefault();
            //Display all artists with 'William' somewhere in their real name
            IEnumerable <Artist> william = Artists.Where(art => art.RealName.Contains("William"));
            //Display the 3 oldest artist from Atlanta
            IEnumerable <Artist> atlanteans = Artists.Where(art => art.Hometown == "Atlanta").OrderByDescending(art => art.Age).Take(3);
            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            IEnumerable <Group> notNY = Groups.Join(Artists, gr => gr.Id, art => art.GroupId, (gr, art) => {
                gr.Members.Add(art);
                return(gr);
            }).Where(gr => gr.Members.All(art => art.Hometown != "New York City")).Distinct();
            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            IEnumerable <Group> wutang = Groups.Join(Artists, gr => gr.Id, art => art.GroupId, (gr, art) => {
                gr.Members.Add(art);
                return(gr);
            }).Distinct();



            Console.WriteLine(Groups.Count);
            Console.WriteLine(mountVernon.RealName);
            Console.WriteLine(mountVernon.Age);
            Console.WriteLine($"{bby.RealName},{bby.Age},{bby.ArtistName}");
            foreach (Artist will in william)
            {
                Console.WriteLine($"{will.RealName}");
            }
            foreach (Artist atl in atlanteans)
            {
                Console.WriteLine($"{atl.ArtistName}({atl.RealName})-{atl.Age}");
            }
            foreach (Group meme in notNY)
            {
                Console.WriteLine($"{meme.GroupName}");
            }
            foreach (var gr in wutang)
            {
                if (gr.GroupName == "Wu-Tang Clan")
                {
                    foreach (Artist meme in gr.Members)
                    {
                        Console.WriteLine($"{meme.ArtistName}-{meme.RealName}");
                    }
                }
            }
        }
Exemplo n.º 5
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?

            Artist buddy = Artists.SingleOrDefault(person => person.Hometown == "Mount Vernon");

            Console.WriteLine(buddy.RealName);
            Console.WriteLine(buddy.Age);

            //Who is the youngest artist in our collection of artists?

            IEnumerable <Artist> orderedAges = Artists.OrderBy(person => person.Age);
            Artist youngBuddy = orderedAges.FirstOrDefault();

            Console.WriteLine($"{youngBuddy.ArtistName} is from {youngBuddy.Hometown}, but their real name is {youngBuddy.RealName} and they are {youngBuddy.Age} years old, making them the youngest on the list.");

            //Display all artists with 'William' somewhere in their real name

            IEnumerable <Artist> WhereMyWillies = Artists.Where(pal => pal.RealName.Contains("William"));

            foreach (Artist willy in WhereMyWillies)
            {
                Console.WriteLine($"{willy.ArtistName}'s real name is {willy.RealName}.");
            }

            //Display the 3 oldest artist from Atlanta

            IEnumerable <Artist> elders        = Artists.Where(person => person.Hometown == "Atlanta");
            IEnumerable <Artist> orderedElders = elders.OrderByDescending(dude => dude.Age);
            IEnumerable <Artist> takenElders   = orderedElders.Take(3);

            foreach (Artist eldie in takenElders)
            {
                Console.WriteLine($"My name is {eldie.RealName} and I am {eldie.Age} years old.");
            }

            //Display all groups with names less than 8 characters in length.

            IEnumerable <Group> groups = Groups.Where(grp => grp.GroupName.Length < 8);

            foreach (Group g in groups)
            {
                Console.WriteLine($"The length of this group name, {g.GroupName}, is less than 8 characters.");
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Console.WriteLine(Groups.Count);
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist theOne = Artists.FirstOrDefault(art => art.Hometown == "Mount Vernon");

            System.Console.WriteLine(theOne.ArtistName + " " + theOne.Age);

            //Who is the youngest artist in our collection of artists?
            Artist youngest = Artists.OrderByDescending(a => a.Age).Last();

            Console.WriteLine(youngest.ArtistName + " " + youngest.Age);

            //Display all artists with 'William' somewhere in their real name
            IEnumerable <Artist> certainArtists = Artists.Where(art => art.RealName.Contains("William"));

            foreach (var a in certainArtists)
            {
                System.Console.WriteLine(a.RealName + " " + a.ArtistName);
            }

            //Display all groups with names less than 8 characters in length
            IEnumerable <Group> shortName = Groups.Where(g => g.GroupName.Length < 8);

            foreach (var g in shortName)
            {
                System.Console.WriteLine(g.GroupName);
            }

            //Display the 3 oldest artist from Atlanta
            IEnumerable <Artist> oldestArtists = Artists.Where(art => art.Hometown == "Atlanta").OrderByDescending(art => art.Age).Take(3);

            foreach (var a in oldestArtists)
            {
                System.Console.WriteLine(a.ArtistName + " " + a.Age);
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            var Id = Artists.Where(a => a.Hometown != "New York City").Select(a => a.GroupId);

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'

            var memberArtists = Groups.Where(g => g.GroupName == "Wu-Tang Clan").Select(g => g.Members.Select(m => m.ArtistName));

            foreach (var a in memberArtists)
            {
                Console.WriteLine(a);
            }
        }
Exemplo n.º 7
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            List <Artist> mountV = Artists
                                   .Where(i => i.Hometown == "Mount Vernon")
                                   .ToList();

            string mountVArt = $"The only artist in Mount Verson is {mountV[0].RealName}, age {mountV[0].Age}.";

            System.Console.WriteLine(mountVArt);

            //Who is the youngest artist in our collection of artists?
            List <Artist> age = Artists
                                .OrderBy(i => i.Age)
                                .ToList();

            string youngest = $"The youngest artist is {age[0].RealName}, age {age[0].Age}.";

            System.Console.WriteLine(youngest);

            //Display all artists with 'William' somewhere in their real name
            List <Artist> willy = Artists
                                  .Where(i => i.RealName
                                         .Contains("William"))
                                  .ToList();

            string willies = $"There are {willy.Count} artist that contain the name 'William', there names are:";

            for (int i = 0; i < willy.Count; i++)
            {
                willies += $" {willy[i].RealName},";
            }
            System.Console.WriteLine(willies);

            //Display the 3 oldest artist from Atlanta
            List <Artist> old = Artists
                                .Where(i => i.Hometown == "Atlanta")
                                .OrderByDescending(i => i.Age)
                                .ToList();
            string oldest = $"The three oldest artists from Atlanta are {old[0].RealName} age {old[0].Age}, {old[1].RealName} age {old[1].Age}, and {old[2].RealName} age {old[2].Age}.";

            System.Console.WriteLine(oldest);

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 8
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            List <Artist> FromMV = Artists.Where(a => a.Hometown == "Mount Vernon").ToList();

            System.Console.WriteLine($"There are {FromMV.Count} artists from Mount Vernon.");

            //Who is the youngest artist in our collection of artists?
            List <Artist> OldestToYoungest = Artists.OrderByDescending(a => a.Age).ToList();
            Artist        YoungestArtist   = OldestToYoungest.Last();

            System.Console.WriteLine($"{YoungestArtist.ArtistName} is the youngest artist on the list.");

            //Display all artists with 'William' somewhere in their real name
            List <Artist> Williams = Artists.Where(a => a.RealName.Contains("William")).ToList();

            System.Console.WriteLine($"Here are real names all of the artists named 'William' or with a last name of 'Williams' in the original list:");
            foreach (Artist a in Williams)
            {
                System.Console.WriteLine($"{a.RealName}");
            }

            //Display the 3 oldest artist from Atlanta
            List <Artist> FromATL             = Artists.Where(a => a.Hometown == "Atlanta").ToList();
            List <Artist> OldestToYoungestATL = FromATL.OrderByDescending(a => a.Age).ToList();

            System.Console.WriteLine("The three oldest artists on the original list who are from Atlanta are:");
            for (int i = 0; i <= 2; i++)
            {
                System.Console.WriteLine($"{OldestToYoungest[i].RealName}");
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Console.WriteLine($"There are {Groups.Count} groups, apparently.");

            System.Console.WriteLine("One of these groups is worth particular note, as it is said they are not to be challenged or confronted lightly.");
            System.Console.WriteLine("Their names are:");
            List <Artist> WuTangClan = Artists.Where(a => a.GroupId == 1).ToList();

            foreach (Artist a in WuTangClan)
            {
                System.Console.WriteLine($"{a.ArtistName}");
            }
            System.Console.WriteLine("Together, they are known as 'The Wu-Tang Clan.'");
        }
Exemplo n.º 9
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            IEnumerable <Artist> Mountvernonartist = Artists.Where(a => a.Hometown == "Mount Vernon");

            foreach (var b in Mountvernonartist)
            {
                System.Console.WriteLine(b.ArtistName + " and " + b.Hometown);
            }
            Console.WriteLine("\n~~~~~~~~~\n");

            //Who is the youngest artist in our collection of artists?
            int    YoungestArtist = Artists.Min(b => b.Age);
            Artist artistname     = Artists.FirstOrDefault(b => b.Age == YoungestArtist);
            {
                System.Console.WriteLine(YoungestArtist + "" + artistname.RealName);
            }
            //Display all artists with 'William' somewhere in their real name
            IEnumerable <Artist> Wartists = Artists.Where(b => b.RealName.Contains("William"));

            System.Console.WriteLine("These artist's names are William");
            foreach (var Artist in Wartists)
            {
                System.Console.WriteLine(Artist.RealName);
            }
            System.Console.WriteLine(".......................................................");


            //Display the 3 oldest artist from Atlanta
            var atOldest = Artists
                           .Where(art => art.Hometown == "Atlanta")
                           .OrderByDescending(art => art.Age)
                           .Take(3);

            System.Console.WriteLine("The three oldest artists from atlanta =");
            foreach (var artist in atOldest)
            {
                System.Console.WriteLine(artist.ArtistName);
            }
            System.Console.WriteLine(".....................................................");

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 10
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist mv = Artists.FirstOrDefault(a => a.Hometown == "Mount Vernon");

            Console.WriteLine($"{mv.ArtistName} is from {mv.Hometown}");

            //Who is the youngest artist in our collection of artists?

            // orderby on age, pick the first OR on age desc, pick the last
            Artist youngest = Artists.OrderByDescending(a => a.Age)
                              .LastOrDefault();

            Artist youngest2 = Artists.FirstOrDefault(
                a => a.Age == Artists.Min(ar => ar.Age)
                );



            //Display all artists with 'William' somewhere in their real name
            var williams = Artists
                           .Where(a => a.RealName.ToLower()
                                  .Contains("william"))
                           .Select(a => new { real = a.RealName, alias = a.ArtistName }).ToList();

            //Display the 3 oldest artist from Atlanta
            var OGs = Artists
                      .Where(a => a.Hometown == "Atlanta")
                      .OrderByDescending(a => a.Age)
                      // LIMIT 3
                      .Take(3);


            int[]    nums    = { 1, 4, 6, 7 };
            string[] strNums = nums.Select(num => num.ToString()).ToArray();

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            var groupsNotFromNy = Groups.Where(
                g => g.Members.Any(m => m.Hometown != "New York City")
                ).ToArray();



            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Console.WriteLine(Groups.Count);
        }
Exemplo n.º 11
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is 2 artists in this collection from Mount Vernon, what is their name and age?
            List <Artist> MountVernonArtists = Artists.Where(a => a.Hometown == "Mount Vernon").ToList();

            foreach (Artist a in MountVernonArtists)
            {
                System.Console.WriteLine($"#1: {a.ArtistName} {a.Age}");
            }
            //Who is the youngest artist in our collection of artists?
            Artist YoungestArtist = Artists.OrderBy(a => a.Age).First();

            System.Console.WriteLine($"#2: {YoungestArtist.ArtistName}: {YoungestArtist.Age}");

            //Display all artists with 'William' somewhere in their real name
            List <Artist> ArtistsWilliam = Artists.Where(a => a.RealName.Contains("William")).ToList();

            foreach (Artist a in ArtistsWilliam)
            {
                System.Console.WriteLine($"#3: {a.RealName}");
            }
            //Display the 3 oldest artist from Atlanta
            List <Artist> AllArtistsAtlanta = Artists.Where(a => a.Hometown == "Atlanta").OrderByDescending(a => a.Age).ToList();

            foreach (Artist a in AllArtistsAtlanta)
            {
                System.Console.WriteLine($"4b: {a.RealName} - {a.Age}");
            }


            List <Artist> ThreeOldestArtistsAtlanta = Artists.Where(a => a.Hometown == "Atlanta").OrderByDescending(a => a.Age).Take(3).ToList();

            foreach (Artist a in ThreeOldestArtistsAtlanta)
            {
                System.Console.WriteLine($"4a: {a.RealName} - {a.Age}");
                System.Console.WriteLine();
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            // IEnumerable<Group> AllGroupsNotNY = Groups.Where(a => a.Members == "NewYork");


            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 12
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist MtVernonArtist = Artists.FirstOrDefault(artist => artist.Hometown == "Mount Vernon");

            Console.WriteLine(MtVernonArtist.ArtistName);
            Console.WriteLine(MtVernonArtist.Age);
            // Name: DMX
            // Age: 46

            //Who is the youngest artist in our collection of artists?
            Artist YoungestArtist = Artists.FirstOrDefault(art => art.Age == Artists.Min(artist => artist.Age));

            Console.WriteLine(YoungestArtist.ArtistName);
            Console.WriteLine(YoungestArtist.Age);
            // Youngest artist: Chance the Rapper, 23

            //Display all artists with 'William' somewhere in their real name
            List <Artist> AllWilliams = Artists.Where(artist => artist.RealName.Contains("William")).ToList();

            PrintEach(AllWilliams);
            // Bryan Williams, Robert Williams, William Roberts, William Griffin

            //Display the 3 oldest artist from Atlanta
            List <Artist> OldestArtistsFrAtlanta = Artists.Where(artist => artist.Hometown == "Atlanta").OrderByDescending(artist => artist.Age).Take(3).ToList();

            PrintEach(OldestArtistsFrAtlanta);
            // 3 oldest artists from Atlanta: Ludacris (39), Andre 3000 (41), Lil Jon (45)

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            List <Group> GroupsNotNYC = Groups.Where(group => group.Members.All(member => member.Hometown != "New York City")).ToList();

            PrintEach(GroupsNotNYC);

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            List <IEnumerable <string> > WuTangClan = Groups.Where(group => group.GroupName == "Wu-Tang Clan").Select(group => group.Members.Select(u => u.ArtistName)).ToList();

            foreach (var group in WuTangClan)
            {
                foreach (var member in group)
                {
                    Console.WriteLine(member);
                }
            }
        }
Exemplo n.º 13
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?

            Artist mtVernonArtist = Artists.FirstOrDefault(a => a.Hometown == "Mount Vernon");

            Console.WriteLine($"The only artist from Mt Vernon is {mtVernonArtist.ArtistName} (Age: {mtVernonArtist.Age}), who was born as {mtVernonArtist.RealName}.");


            //Who is the youngest artist in our collection of artists?

            Artist youngestArtist = Artists.FirstOrDefault(a => a.Age == Artists.Min(age => age.Age));

            Console.WriteLine($"The youngest artist is {youngestArtist.ArtistName} (Age: {youngestArtist.Age}).  Born as {youngestArtist.RealName}.");

            //Display all artists with 'William' somewhere in their real name

            IEnumerable <Artist> Williams = Artists.Where(a => a.RealName.Contains("William")).ToList();

            Console.WriteLine("The following artists all have William somewhere in their name");
            foreach (Artist artist in Williams)
            {
                Console.WriteLine($"Name: {artist.ArtistName} Real Name: {artist.RealName} ");
            }


            //Display the 3 oldest artist from Atlanta

            IEnumerable <Artist> topThreeOldest = Artists
                                                  .Where(a => a.Hometown == "Atlanta")
                                                  .OrderByDescending(a => a.Age)
                                                  .Take(3);

            Console.WriteLine("The following are the 3 oldest artists from Atlanta");
            foreach (Artist artist in topThreeOldest)
            {
                Console.WriteLine($"Name: {artist.ArtistName} Real Name: {artist.RealName}");
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Console.WriteLine(Groups.Count);
        }
Exemplo n.º 14
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            // List<Artist> MountVern = Artists.Where(a => a.Hometown == "Mount Vernon").ToList();
            // System.Console.WriteLine($"Artist Name from Mount Vernon: {MountVern[0].ArtistName}; Age: {MountVern[0].Age}");

            //Who is the youngest artist in our collection of artists?
            // Artist youngest = Artists.OrderByDescending(a => a.Age).Last();
            // System.Console.WriteLine($"Youngest Artist Name: {youngest.ArtistName}; Age: {youngest.Age}");

            //Display all artists with 'William' somewhere in their real name
            // List<Artist> William = Artists.Where(a => a.RealName.Contains("William")).ToList();
            // foreach(var bill in William){
            //     System.Console.WriteLine($"Real Name: {bill.RealName}; Artist Name: {bill.ArtistName}");
            // }

            // Display all groups with names less than 8 characters in length.
            // List<Group> name = Groups.Where(g => g.GroupName.Length < 8).ToList();
            // System.Console.WriteLine(name.Count);
            // foreach (var group in name){
            //     System.Console.WriteLine($"Group Name: {group.GroupName}");
            // }

            //Display the 3 oldest artist from Atlanta
            // List<Artist> FromAtlanta = Artists.Where(a => a.Hometown == "Atlanta").OrderByDescending(a => a.Age).Take(3).ToList();
            // foreach (var a in FromAtlanta){
            //     System.Console.WriteLine(a.ArtistName);
            // }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City


            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Group WuTang = Groups.First(g => g.GroupName == "Wu-Tang Clan");

            foreach (var artist in WuTang.Members)
            {
                System.Console.WriteLine($"Name: {artist.ArtistName}");
            }


            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 15
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist vernonArtist = Artists.FirstOrDefault(artist => artist.Hometown == "Mount Vernon");

            Console.WriteLine(vernonArtist.ArtistName, vernonArtist.Age);

            //Who is the youngest artist in our collection of artists?
            List <Artist> youngestArtist = Artists.OrderBy(artists => artists.Age).ToList();

            Console.WriteLine(youngestArtist[0].ArtistName);

            //Display all artists with 'William' somewhere in their real name
            List <Artist> william = Artists.Where(artists => artists.RealName.Contains("William")).ToList();

            Console.WriteLine(william);
            // Display all groups with names less than 8 characters in length.
            List <Group> eightCharacters = Groups.Where(groups => groups.GroupName.Length == 8).ToList();

            Console.WriteLine(eightCharacters);
            //Display the 3 oldest artist from Atlanta
            List <Artist> ATL = Artists.OrderByDescending(artists => artists.Hometown.Contains("Atlanta")).ToList();

            Console.WriteLine(ATL[0].ArtistName);
            Console.WriteLine(ATL[1].ArtistName);
            Console.WriteLine(ATL[2].ArtistName);
            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            var joinedGroups = Groups.Join(Artists,
                                           g => g.Id,
                                           a => a.GroupId,
                                           (joinedGroups, joinedA) => {
                joinedGroups.Members.Add(joinedA);
                return(joinedGroups);
            }).ToList();

            List <Group> notNewYork = joinedGroups.Where(g => g.Members.Any(a => a.Hometown != "New York City")).ToList();

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // List<Group> wuTangClan = joinedGroups.Where(g => g.GroupName.Contains("Wu-Tang Clan").Select(g.Members)).ToList();
            List <Artist> WTmembers = Groups.FirstOrDefault(g => g.GroupName == "Wu-Tang Clan").Members;

            foreach (var member in WTmembers)
            {
                Console.WriteLine(member.ArtistName);
            }
            Console.WriteLine(Groups.Count);
        }
Exemplo n.º 16
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            var ArtistFromMountVernon = from artist in Artists where artist.Hometown == "Mount Vernon" select new { artist.RealName };

            foreach (var i in ArtistFromMountVernon)
            {
                Console.WriteLine(i);
            }
            //Who is the youngest artist in our collection of artists?
            var YoungestArtist = Artists.OrderBy(artist => artist.Age).First();

            Console.WriteLine(YoungestArtist.ArtistName + YoungestArtist.Age);

            var YoungestAge     = Artists.Min(artist => artist.Age);
            var YoungestArtist2 = Artists.Where(artist => artist.Age == YoungestAge);

            foreach (var i in YoungestArtist2)
            {
                Console.WriteLine(i.ArtistName + i.Age);
            }

            //Display all artists with 'William' somewhere in their real name
            var ArtistNamedWilliam = Artists.Where(artist => artist.RealName.Contains("William"));

            foreach (var i in ArtistNamedWilliam)
            {
                Console.WriteLine(i.ArtistName);
            }
            //Display the 3 oldest artist from Atlanta
            var ArtistFromAtlanta = Artists.Where(artist => artist.Hometown == "Atlanta");
            var OldestThree       = ArtistFromAtlanta.OrderByDescending(artist => artist.Age).Take(3);

            foreach (var i in OldestThree)
            {
                Console.WriteLine(i.ArtistName);
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 17
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist artist = Artists.FirstOrDefault(city => city.Hometown == "Mount Vernon");

            System.Console.WriteLine(artist.ArtistName);
            //Who is the youngest artist in our collection of artists?
            int smallest_num = Artists.Min(age => age.Age);
            var youngest     = Artists.Where(age => age.Age == smallest_num);

            foreach (var art in youngest)
            {
                System.Console.WriteLine(art.ArtistName + " : " + art.Age);
            }

            System.Console.WriteLine("\n");

            //Display all artists with 'William' somewhere in their real name
            var willIam = Artists.Where(name => name.RealName.Contains("William"));

            foreach (var will in willIam)
            {
                System.Console.WriteLine(will.ArtistName);
            }

            System.Console.WriteLine("\n");

            //Display the 3 oldest artist from Atlanta
            var ATL     = Artists.Where(artst => artst.Hometown == "Atlanta");
            var oldest3 = ATL.OrderByDescending(age => age.Age).Take(3);

            foreach (var oldest in oldest3)
            {
                System.Console.WriteLine(oldest.ArtistName + " from " + oldest.Hometown + " age :" + oldest.Age);
            }


            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 18
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist mountVern = Artists.FirstOrDefault(artist => artist.Hometown == "Mount Vernon");

            Console.WriteLine("The Artist from Mount Vernon is :");
            Console.WriteLine(mountVern.RealName);
            Console.WriteLine();

            //Who is the youngest artist in our collection of artists?
            int    age      = Artists.Min(artist => artist.Age);
            Artist youngest = Artists.FirstOrDefault(artist => artist.Age == age);

            Console.WriteLine("The youngest Artist in the Group is :");
            Console.WriteLine(youngest.ArtistName + ", " + youngest.Age + " years old");
            Console.WriteLine();

            //Display all artists with 'William' somewhere in their real name
            List <Artist> wills = Artists.Where(artist => artist.RealName.Contains("William")).ToList();

            wills.ForEach(i => Console.WriteLine("{0}\t", i.RealName + " aka " + i.ArtistName));
            Console.WriteLine();

            //Display the 3 oldest artist from Atlanta
            List <Artist> hotlanta = Artists.Where(artist => artist.Hometown == "Atlanta").OrderByDescending(artist => artist.Age).Take(3).ToList();

            hotlanta.ForEach(i => Console.WriteLine("{0}\t", i.RealName + " aka " + i.ArtistName + ", " + i.Age + " years old"));
            Console.WriteLine();

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            IEnumerable <string> notNyc = Artists.Where(artist => artist.Hometown != "New York City").Join(Groups,
                                                                                                           artId => artId.GroupId,
                                                                                                           grpId => grpId.Id,
                                                                                                           (artId, grpId) =>
            {
                return(artId.ArtistName + ", " + grpId.GroupName);
            });

            Console.WriteLine(notNyc);

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
        }
Exemplo n.º 19
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            var artist = Artists.Where(
                a => a.Hometown == "Mount Vernon")
                         .Select(myArtist => new Artist {
                RealName = myArtist.RealName, Age = myArtist.Age
            });

            foreach (var art in artist)
            {
                System.Console.WriteLine($"Artists from Mount Vernon: Artist Name: {art.ArtistName} Real Name: {art.RealName} Age:{art.Age}");
            }



            //Who is the youngest artist in our collection of artists?
            var youngest = Artists.OrderByDescending(x => x.Age).Last();

            System.Console.WriteLine($"Youngest artist: Artist Name: {youngest.ArtistName} Real Name: {youngest.RealName} Age: {youngest.Age}");

            //Display all artists with 'William' somewhere in their real name
            var williams = Artists.Where(will => will.RealName.Contains("William"));

            foreach (var will in williams)
            {
                System.Console.WriteLine(will.RealName);
            }

            //Display the 3 oldest artist from Atlanta
            var threeoldest = Artists.Where(a => a.Hometown == "Atlanta").OrderByDescending(x => x.Age).Take(3);

            foreach (var old in threeoldest)
            {
                System.Console.WriteLine($"Artist Name: {old.ArtistName} Real Name: {old.RealName} Age: {old.Age}");
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
        }
Exemplo n.º 20
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            var VernArtist = Artists.Where(art => art.Hometown.Contains("Mount Vernon")) //Where grabs the artist the artist
                             .Select(art => new { art.Age, art.ArtistName });            //Select grabs the artist att

            foreach (var artist in VernArtist)
            {
                Console.WriteLine("Artist: " + artist.ArtistName + " Age: " + artist.Age);
            }

            //Who is the youngest artist in our collection of artists?
            var youngest = Artists.OrderByDescending(art => art.Age).Last();

            Console.WriteLine("Artist: " + youngest.ArtistName + " Age: " + youngest.Age);

            //Display all artists with 'William' somewhere in their real name
            var will = Artists.Where(art => art.RealName.Contains("William"))
                       .Select(art => art.RealName);

            foreach (var artist in will)
            {
                Console.WriteLine(artist);
            }

            //Display the 3 oldest artist from Atlanta
            var atlanta = Artists.Where(art => art.Hometown == "Atlanta").OrderByDescending(art => art.Age).Take(3);

            foreach (var artist in atlanta)
            {
                Console.WriteLine("Artist: " + artist.ArtistName + " Age: " + artist.Age + " Hometown: " + artist.Hometown);
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Console.WriteLine(Groups.Count);
        }
Exemplo n.º 21
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            IEnumerable <Artist> myArtist = Artists.Where(x => x.Hometown == "Mount Vernon").ToList();

            foreach (var artist in myArtist)
            {
                System.Console.WriteLine($"Real Name: {artist.RealName} Age: {artist.Age}");
            }

            //Who is the youngest artist in our collection of artists?
            var youngArtist = Artists.OrderBy(x => x.Age).First();

            System.Console.WriteLine($"The youngest artist is: {youngArtist.ArtistName} with an age of {youngArtist.Age}");

            //Display all artists with 'William' somewhere in their real name
            var williams = Artists.Where(a => a.RealName.Contains("William")).Select(a => a.RealName);

            foreach (var william in williams)
            {
                Console.WriteLine(william);
            }

            //Display the 3 oldest artist from Atlanta
            var atlanta = Artists.Where(a => a.Hometown == "Atlanta").OrderByDescending(a => a.Age).Take(3);

            foreach (var artist in atlanta)
            {
                Console.WriteLine(artist.RealName + " is " + artist.Age + " years old and is from " + artist.Hometown);
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Console.WriteLine(Groups.Count);
        }
Exemplo n.º 22
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist a1 = Artists.FirstOrDefault(art => art.Hometown == "Mount Vernon");

            Console.WriteLine(a1.ArtistName + " : " + a1.Age);

            //Who is the youngest artist in our collection of artists?
            Artist a2 = (Artist)Artists.OrderBy(art => art.Age).First();

            Console.WriteLine(a2.ArtistName + " : " + a2.Age);

            //Display all artists with 'William' somewhere in their real name
            List <Artist> a3 = Artists.Where(art => art.ArtistName.Contains("William") || art.RealName.Contains("William")).ToList();

            foreach (Artist afor in a3)
            {
                Console.WriteLine(afor.ArtistName + " : " + afor.Age);
            }
            //Display the 3 oldest artist from Atlanta
            List <Artist> a4 = Artists
                               .OrderBy(art => art.Age)
                               .Where(art => art.Hometown == "Atlanta")
                               .Take(3).ToList();

            foreach (Artist afor in a4)
            {
                Console.WriteLine(afor.ArtistName + " : " + afor.Age);
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Console.WriteLine(Groups.Count);
        }
Exemplo n.º 23
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist mtVerArtist = Artists.FirstOrDefault(who => who.Hometown == "Mount Vernon");
            // Console.WriteLine(mtVerArtist.ArtistName + " " + mtVerArtist.Age);


            //Who is the youngest artist in our collection of artists?
            Artist youngest = Artists.FirstOrDefault(young => young.Age == Artists.Min(y => y.Age));
            // Console.WriteLine(youngest.ArtistName);

            //Display all artists with 'William' somewhere in their real name
            List <Artist> williamArtists = Artists.Where(name => name.RealName.Contains("William")).ToList();
            // PrintEach(williamArtists);


            // //Display the 3 oldest artists from Atlanta
            // List<Artist> atlArtists = Artists.Where(loc => loc.Hometown == "Atlanta" && loc.Age.OrderByDecending == ).ToList();
            // PrintEach(atlArtists);

            IEnumerable <Artist> atlArtists = Artists
                                              .Where(loc => loc.Hometown == "Atlanta")
                                              .OrderByDescending(a => a.Age)
                                              .Take(3);

            PrintEach(atlArtists);


            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 24
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist mtVernon = Artists.FirstOrDefault(artage => artage.Hometown == "Mount Vernon");

            System.Console.WriteLine($"Name: {mtVernon.RealName}, Age: {mtVernon.Age}");
            //Who is the youngest artist in our collection of artists?
            Artist youngone = Artists.OrderBy(a => a.Age).First();

            System.Console.WriteLine($"Name: {youngone.RealName}, Age: {youngone.Age} ");

            //Display all artists with 'William' somewhere in their real name
            List <Artist> realWilliam = Artists.Where(a => a.RealName.Contains("Wil")).ToList();

            foreach (Artist wil in realWilliam)
            {
                System.Console.WriteLine($"{wil.RealName}");
            }
            //Display the 3 oldest artist from Atlanta
            List <Artist> oldestAtlanta = Artists.Where(h => h.Hometown == "Atlanta").OrderByDescending(a => a.Age).Take(3).ToList();

            foreach (Artist age in oldestAtlanta)
            {
                System.Console.WriteLine($"Name: {age.ArtistName}, Age: {age.Age}");
            }
            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Console.WriteLine(Groups.Count);
        }
Exemplo n.º 25
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            // Artist MtVernon = Artists.FirstOrDefault(loc => loc.Hometown == "Mount Vernon");
            // System.Console.WriteLine(MtVernon.RealName);

            //Who is the youngest artist in our collection of artists?
            Artist Youngest = Artists.OrderBy(age => age.Age).FirstOrDefault();
            // System.Console.WriteLine(Youngest.ArtistName + " is the youngest at age " + Youngest.Age);

            //Display all artists with 'William' somewhere in their real name
            IEnumerable <Artist> Williams = from temp in Artists.Where(will => will.RealName.Contains("William")) select temp;

            foreach (var william in Williams)
            {
                System.Console.WriteLine(william.RealName);
            }
            //Display the 3 oldest artist from Atlanta
            IEnumerable <Artist> Oldest = Artists.OrderByDescending(age => age.Age).Take(3);

            foreach (var i in Oldest)
            {
                System.Console.WriteLine(i.ArtistName + " " + i.Age);
            }
            //(Optional) Display the Group Name of all groups that have members that are not from New York City

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 26
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            System.Console.WriteLine("That Guy From Mount Vernon");
            IEnumerable <Artist> thatGuyFromMtVernon = Artists.Where(a => a.Hometown == "Mount Vernon");

            foreach (var a in thatGuyFromMtVernon)
            {
                System.Console.WriteLine("Name: " + a.ArtistName + " Age: " + a.Age);
            }

            //Who is the youngest artist in our collection of artists?
            // int yAge = Artists.Min(artist => artist.Age);
            System.Console.WriteLine("Youngest Gun");
            IEnumerable <Artist> youngestArtist = Artists.Where(artist => artist.Age == Artists.Min(a => a.Age));

            foreach (var a in youngestArtist)
            {
                System.Console.WriteLine("Name: " + a.ArtistName + " Age: " + a.Age);
            }
            //Display all artists with 'William' somewhere in their real name
            System.Console.WriteLine("Billys");
            IEnumerable <Artist> billys = Artists.Where(artist => artist.RealName.Contains("William"));

            foreach (var a in billys)
            {
                System.Console.WriteLine("Name: " + a.ArtistName + " Age: " + a.Age);
            }
            // //Display the 3 oldest artist from Atlanta
            System.Console.WriteLine("Fossils");
            IEnumerable <Artist> fossils = Artists.OrderByDescending(artist => artist.Age)
                                           .Take(3);

            foreach (var a in fossils)
            {
                System.Console.WriteLine("Name: " + a.ArtistName + " Age: " + a.Age);
            }
            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            System.Console.WriteLine("Non New Yorkers");
            IEnumerable <string> notApples = Artists.Where(artist => artist.Hometown != "New York City")
                                             .Join(Groups,
                                                   artist => artist.GroupId,
                                                   group => group.Id,
                                                   (artists, group) =>
            {
                return(group.GroupName);
            }).Distinct().ToArray();

            foreach (var member in notApples)
            {
                System.Console.WriteLine(member);
            }
            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            System.Console.WriteLine("Wu-Tang Clan");
            IEnumerable <string> wuTangClan = Groups
                                              .Where(group => group.GroupName == "Wu-Tang Clan")
                                              .Join(Artists,
                                                    group => group.Id,
                                                    artist => artist.GroupId,
                                                    (group, artist) =>
            {
                return(artist.ArtistName + " " + artist.RealName + " " + group.GroupName);
            });

            foreach (var member in wuTangClan)
            {
                System.Console.WriteLine(member);
            }
            // Console.WriteLine(Groups.Count);
        }
Exemplo n.º 27
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            // (the same as the next line) List<Artist> FromMtVernon = Artists.Where(artist => artist.Hometown == "Mount Vernon").ToList();
            // IEnumerable<Artist> FromMtVernon = Artists.Where(artist => artist.Hometown == "Mount Vernon");

            // Console.WriteLine(FromMtVernon);
            // PrintItems(FromMtVernon);

            // Artist FromMt = Artists.FirstOrDefault(art => art.Hometown =="Mount Vernon");
            // Console.WriteLine(FromMt);
            // FromMtVernon.Add

            //Who is the youngest artist in our collection of artists?
            // int youngestValue = Artists.Min(a => a.Age);
            // Artist youngest = Artists.FirstOrDefault(artist => artist.Age == Artists.Min(a => a.Age));
            // Console.WriteLine(youngest.Age);
            //.Where(artist => artist.Age == Artists.Min(artist => artist.Age));

            //Display all artists with 'William' somewhere in their real name
            // IEnumerable<Artist> NamedWill = Artists.Where(artist => artist.RealName.Contains("William"));
            // Console.WriteLine("Hello");
            // PrintItems(NamedWill);


            //Display the 3 oldest artist from Atlanta
            // IEnumerable<Artist>  Oldest = Artists.Where(artist => artist.Hometown == "Atlanta").OrderByDescending(a => a.Age).Take(3);
            // foreach (var item in Oldest)
            // {
            //     Console.WriteLine(item.ArtistName);

            // }


            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            // IEnumerable<Artist> notNewY = Artists.Where(artist => artist.Hometown != "New York City");
            // foreach (var item in notNewY)
            // {
            //     Console.WriteLine(item.ArtistName);
            // }


            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
            // int GroupId = Artist.Where(args => a.)
            IEnumerable <Group> Wu = Groups.Where(artist => artist.GroupName == "Wu-Tang-Clan");

            foreach (var item in Wu)
            {
                Console.WriteLine(item.Members);
            }

            // int youngestValue = Artists.Min(a => a.Age);
            // Artist youngest = Artists.FirstOrDefault(artist => artist.Age == Artists.Min(a => a.Age));
        }
Exemplo n.º 28
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist mountArtist = Artists.FirstOrDefault(art => art.Hometown == "Mount Vernon");

            System.Console.WriteLine(mountArtist.ArtistName);
            System.Console.WriteLine(mountArtist.Age);
            System.Console.WriteLine("************************");

            //Who is the youngest artist in our collection of artists?
            int    youngestAge    = Artists.Min(art => art.Age);
            Artist youngestArtist = Artists.FirstOrDefault(art => art.Age == youngestAge);

            System.Console.WriteLine(youngestArtist.ArtistName + " is " + youngestAge + " years old.");
            System.Console.WriteLine("************************");

            //Display all artists with 'William' somewhere in their real name
            var allWilliam = Artists.Where(art => art.RealName.Contains("William"));

            foreach (var artist in allWilliam)
            {
                System.Console.WriteLine(artist.RealName);
            }
            System.Console.WriteLine("************************");

            //Display the 3 oldest artist from Atlanta
            var atlArtists = Artists
                             .Where(art => art.Hometown == "Atlanta")
                             .OrderByDescending(art => art.Age)
                             .Take(3);

            foreach (var artist in atlArtists)
            {
                System.Console.WriteLine(artist.ArtistName);
            }
            System.Console.WriteLine("************************");

            //Display all groups with names less than 8 characters in length.
            var shortNames = Groups.Where(g => g.GroupName.Length < 8);

            foreach (var group in shortNames)
            {
                Console.WriteLine(group.GroupName);
            }
            Console.WriteLine("*************************************");

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            var groupJoin = Groups
                            .Join(Artists,
                                  (g => g.Id),
                                  (a => a.GroupId),
                                  (joinedGroup, joinedArtist) =>
            {
                joinedGroup.Members.Add(joinedArtist);
                return(joinedGroup);
            })
                            .Distinct()
                            .ToList();
            var notNYC = groupJoin.Where(gj => gj.Members.Any(m => m.Hometown != "New York CIty")).ToList();

            foreach (var group in notNYC)
            {
                System.Console.WriteLine(group.GroupName);
            }
            Console.WriteLine("*************************************");

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            // Console.WriteLine(Groups.Count);
            var clanJoin = Artists
                           .Join(Groups,
                                 (a => a.GroupId),
                                 (g => g.Id),
                                 (joinedArtist, joinedGroup) =>
            {
                return(joinedArtist);
            })
                           .ToList();
            var clanArtists = clanJoin.Where(cj => cj.Group.GroupName == "Wu-Tang Clan");

            foreach (var artist in clanArtists)
            {
                System.Console.WriteLine(artist.ArtistName);
            }
        }
Exemplo n.º 29
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            Artist firstOne = Artists.FirstOrDefault();

            System.Console.WriteLine("#########################");
            System.Console.WriteLine("Name " + firstOne.ArtistName);
            System.Console.WriteLine("Age " + firstOne.Age);

            //Who is the youngest artist in our collection of artists?
            List <Artist> youngest = Artists.OrderBy(a => a.Age).ToList();

            System.Console.WriteLine("Name " + youngest.First().ArtistName);
            System.Console.WriteLine("Age" + youngest.First().Age);

            // Display all artists with 'William' somewhere in their real name
            List <Artist> williamList = Artists.Where(a => a.RealName.Contains("William")).ToList();

            foreach (var w in williamList)
            {
                System.Console.WriteLine("William in name: " + w.RealName);
            }
            // Display all groups with name less than 8 characters in length.
            List <Group> nameList = Groups.Where(g => g.GroupName.Length < 8).ToList();

            foreach (var name in nameList)
            {
                System.Console.WriteLine("name less than 8 characters: " + name.GroupName);
            }
            //Display the 3 oldest artist from Atlanta
            List <Artist> ageList = Artists.OrderByDescending(a => a.Age).Take(3).ToList();

            foreach (var a in ageList)
            {
                System.Console.WriteLine("Three oldest " + a.Age);
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            List <Group> groupList = Groups.Where(g => g.Members.TrueForAll(m => m.Hometown != "New York City")).ToList();

            foreach (var g in groupList)
            {
                System.Console.WriteLine("Not from New York: " + g.GroupName);
            }

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Group group = Groups.FirstOrDefault(g => g.GroupName == "Wu-Tang Clan");

            foreach (var g in group.Members)
            {
                System.Console.WriteLine("Wu-Tang: " + g.ArtistName);
            }

            Console.WriteLine(Groups.Count);
        }
Exemplo n.º 30
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = MusicStore.GetData().AllArtists;
            List <Group>  Groups  = MusicStore.GetData().AllGroups;

            //========================================================
            //Solve all of the prompts below using various LINQ queries
            //========================================================

            //There is only one artist in this collection from Mount Vernon, what is their name and age?
            IEnumerable <Artist> justMtVernon = Artists.Where(resulta => resulta.Hometown == "Mount Vernon");

            foreach (var a in justMtVernon)
            {
                Console.WriteLine(a.Age + " and " + a.ArtistName);
            }
            System.Console.WriteLine("\n++++++++++++++\n");

            //Who is the youngest artist in our collection of artists?
            IEnumerable <Artist> youngest = Artists.OrderByDescending(resultb => resultb.Age);
            Artist myYoungest             = youngest.Last();

            System.Console.WriteLine(myYoungest.ArtistName + " and " + myYoungest.Age);
            System.Console.WriteLine("\n++++++++++++++\n");

            //Display all artists with 'William' somewhere in their real name
            IEnumerable <Artist> justWilliam = Artists.Where(resultc => resultc.RealName.Contains("William"));

            foreach (var a in justWilliam)
            {
                Console.WriteLine(a.RealName);
            }
            System.Console.WriteLine("\n++++++++++++++\n");

            //Display all groups with names less than 8 characters in length.
            IEnumerable <Group> eightChars = Groups.Where(resultf => resultf.GroupName.Length < 8);

            foreach (var b in eightChars)
            {
                System.Console.WriteLine(b.GroupName);
            }
            System.Console.WriteLine("\n++++++++++++++\n");

            //Display the 3 oldest artist from Atlanta
            IEnumerable <Artist> oldAtlanta  = Artists.Where(resultd => resultd.Hometown == "Atlanta");
            IEnumerable <Artist> threeOldest = oldAtlanta.OrderByDescending(resulte => resulte.Age);
            int i = 0;

            foreach (var a in threeOldest)
            {
                if (i > 2)
                {
                    break;
                }
                System.Console.WriteLine(a.ArtistName + " and " + a.Age + " and " + a.Hometown);
                i++;
            }
            System.Console.WriteLine("\n++++++++++++++\n");

            //(Optional) Display the Group Name of all groups that have members that are not from New York City


            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            int myGroupId           = 0;
            IEnumerable <Group> wtc = Groups.Where(resultf => resultf.GroupName == "Wu-Tang Clan");

            foreach (var w in wtc)
            {
                myGroupId = w.Id;
            }
            IEnumerable <Artist> wtcOnly = Artists.Where(resultg => resultg.GroupId == myGroupId);

            foreach (var a in wtcOnly)
            {
                System.Console.WriteLine(a.ArtistName);
            }
            System.Console.WriteLine("\n++++++++++++++\n");

            // Console.WriteLine(Groups.Count);
        }