Esempio n. 1
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            System.Console.WriteLine("Hello!");

            //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");

            foreach (var item in artist)
            {
                System.Console.WriteLine(item.RealName);
                System.Console.WriteLine(item.Age);
            }

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

            System.Console.WriteLine(art.ArtistName);
            System.Console.WriteLine(art.Age);

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

            foreach (var i in william)
            {
                System.Console.WriteLine(i.RealName);
            }

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

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

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            var query =
                (from g in Groups
                 join a in Artists.Where(a => a.Hometown != "New York City")
                 on g.Id equals a.GroupId
                 select new { g.GroupName }).Distinct();

            foreach (var i in query)
            {
                System.Console.WriteLine(i.GroupName + " has no members from NYC.");
            }

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            var wutang =
                from g in Groups.Where(g => g.GroupName == "Wu-Tang Clan")
                join a in Artists
                on g.Id equals a.GroupId
                select new { a.ArtistName };

            foreach (var i in wutang)
            {
                System.Console.WriteLine(i.ArtistName + " is in the Wu-Tang Clan.");
            }
        }
Esempio n. 2
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //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 filterFind = Artists.Where(artist => artist.Hometown == "Mount Vernon").Single();

            Console.WriteLine("1. Artist from Mount Vernon");
            Console.WriteLine($"{filterFind.ArtistName} from Mt Vernon is {filterFind.Age}");

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

            Console.WriteLine("2. Youngest artist");
            Console.WriteLine($"{findyoung.ArtistName} is the youngest artist, they are {findyoung.Age}.");

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

            Console.WriteLine("3. Artists with 'William' somewhere in their real name");
            foreach (var artist in Williams)
            {
                Console.WriteLine($"{artist.ArtistName}'s real name is {artist.RealName}");
            }

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

            Console.WriteLine("4. 3 oldests artist from Atlanta");
            foreach (var artist in wiseBois)
            {
                Console.WriteLine($"{artist.ArtistName} is {artist.Age}");
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            Console.WriteLine("5. Group Nmae of all groups that have members not from NYC");

            List <string> notNYCGroups = Artists.
                                         Join(Groups,
                                              artist => artist.GroupId,
                                              group => group.Id,
                                              (artist, group) => {
                artist.Group = group;
                return(artist);
            })
                                         .Where(artist => (artist.Hometown != "New York City" && artist.Group != null))
                                         .Select(artist => artist.Group.GroupName)
                                         .Distinct()
                                         .ToList();

            foreach (var group in notNYCGroups)
            {
                Console.WriteLine(group);
            }
            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
        }
Esempio n. 3
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            System.Console.WriteLine(Groups);

            Artist FromMountVernon = Artists.Where(match => match.Hometown == "Mount Vernon").Single();

            System.Console.WriteLine(FromMountVernon);
            System.Console.WriteLine($"The artist {FromMountVernon.ArtistName} from Mt Vernon is {FromMountVernon.Age} years old");

            Artist Youngest = Artists.OrderBy(artist => artist.Age).First();

            System.Console.WriteLine(Youngest);
            System.Console.WriteLine($"The youngest artist {Youngest.ArtistName} is {Youngest.Age} years old");

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

            System.Console.WriteLine(Williams);
            foreach (var william in Williams)
            {
                System.Console.WriteLine(william.ArtistName + " - " + william.RealName);
            }
            System.Console.WriteLine("***********************");

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

            foreach (var oldie in ThreeOldest)
            {
                System.Console.WriteLine(oldie.ArtistName + " - " + oldie.RealName + " Hometown: " + oldie.Hometown);
            }

            Group WuTang = Groups.Where(group => group.GroupName == "Wu-Tang Clan")
                           .GroupJoin(Artists,
                                      group => group.Id,
                                      artist => artist.GroupId,
                                      (group, artists) => { group.Members = artists.ToList(); return(group); })
                           .Single();

            Console.WriteLine("List of Artist in the Wu-Tang Clan:");
            foreach (var artist in WuTang.Members)
            {
                Console.WriteLine(artist.ArtistName);
            }

            //========================================================
            //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?

            //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'
        }
Esempio n. 4
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //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 FromMtVernon = Artists.Where(artist => artist.Hometown == "Mount Vernon").Single();

            Console.WriteLine($"The artist {FromMtVernon.ArtistName} from Mt Vernon is {FromMtVernon.Age} years old");

            var ArtistMountVernon =
                from artist in Artists
                where artist.Hometown == "Mount Vernon"
                select new { artist.ArtistName, artist.Age };

            foreach (var person in ArtistMountVernon)
            {
                System.Console.WriteLine($"Artist Name: {person.ArtistName}" + "----" + $"Age:{person.Age}");
            }

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

            Console.WriteLine($"The Youngest artist is {Youngest.ArtistName}");

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

            System.Console.WriteLine("These are the artist with the 'RealName' William");
            foreach (var artist in Williams)
            {
                System.Console.WriteLine($"{artist.ArtistName}" + "----" + $"{artist.RealName}");
            }

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

            Console.WriteLine("The three oldest artists from Atlanta are:");
            foreach (var artist in OldestAtlanta)
            {
                Console.WriteLine(artist.ArtistName + " - " + artist.Age);
            }

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

            Console.WriteLine("All groups with names less than 8 in length:");
            foreach (var group in groupByLength)
            {
                Console.WriteLine(group.GroupName);
            }
            //(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'
        }
Esempio n. 5
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //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 FromMtVernon = Artists.Where(artist => artist.Hometown == "Mount Vernon").Single();
            // Console.WriteLine($"{FromMtVernon.ArtistName} is from Mt Vernon and is {FromMtVernon.Age} years old");



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

            // Artist Youngest = Artists.OrderBy(artists => artists.Age).First();
            // System.Console.WriteLine($"The youngest artist from the list is {Youngest.ArtistName}");



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

            // List<Artist> Williams = Artists.Where(artist => artist.RealName.Contains("William")).ToList();
            // Console.WriteLine("The Following artists have William in their real names:");
            // foreach(var artist in Williams) {
            //     Console.WriteLine(artist.ArtistName + " - " + artist.RealName);
            // }


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

            // List<Group> NameLess = Groups.Where(group => group.GroupName.Length < 8).ToList();
            // System.Console.WriteLine("The following groups have less than 8 characters in their names");
            // foreach(var group in NameLess) {
            //     System.Console.WriteLine(group.GroupName);
            // }


            //Display the 3 oldest artist from Atlanta

            // List<Artist> OldestATL = Artists.Where(artist => artist.Hometown == "Atlanta").OrderByDescending(artist => artist.Age).Take(3).ToList();
            // Console.WriteLine("The three oldest artists from Atlanta are:");
            // foreach(var artist in OldestATL) {
            //     Console.WriteLine(artist.ArtistName + " - " + artist.Age);
            // }


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

            // List<string> NotNy = Artists.Join(Groups, artist => artist.GroupId, group => group.Id, (artist, group) => { artist.Group = group; return artist;}).Where(artist => (artist.Hometown != "New York City" && artist.Group != null)).Select(artist => artist.Group.GroupName).Distinct().ToList();
            // Console.WriteLine("All groups with members not from New York City:");
            // foreach(var group in NotNy){
            //     Console.WriteLine(group);
            // }


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

            List <Artist> WuTang = Artists.Where(artist => artist.GroupId == 1).ToList();

            System.Console.WriteLine($"The members of the Wu Tang Clan are:");
            foreach (var artist in WuTang)
            {
                System.Console.WriteLine(artist.ArtistName);
            }
            System.Console.WriteLine("And U-God, and Masta Killa, and Cappadonna");
            System.Console.WriteLine("PROTECT YA NECK. BRING THE MOTHA F****N RUCKUS");
        }
Esempio n. 6
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //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("");
            System.Console.WriteLine("There is only one artist in this collection from Mount Vernon, what is their name and age?");

            var foundArtistInMtVernon = from artist in Artists
                                        where artist.Hometown == "Mount Vernon"
                                        select new { artist.RealName, artist.Age };

            foreach (var i in foundArtistInMtVernon)
            {
                System.Console.WriteLine(i);
            }


            // IEnumerable<Artist> foundArtistInMtVernonList = Artists.Where(str => str.Hometown == "Mount Vernon");

            // foreach(var i in foundArtistInMtVernonList)
            // {
            //     System.Console.WriteLine(i.RealName + " " + i.Age);
            // }

            //Who is the youngest artist in our collection of artists?
            // var foundYoungestArtist = from artist in Artists
            //                           orderby artist.Age
            //                           select new {artist.RealName, artist.Age};

            // System.Console.WriteLine(foundYoungestArtist.First().RealName + " " + foundYoungestArtist.First().Age);


            System.Console.WriteLine("");
            System.Console.WriteLine("Who is the youngest artist in our collection of artists?");
            var foundYoungestArtistList = Artists.OrderBy(x => x.Age).First();

            System.Console.WriteLine(foundYoungestArtistList.RealName + " " + foundYoungestArtistList.Age);

            //Display all artists with 'William' somewhere in their real name
            System.Console.WriteLine("");
            System.Console.WriteLine("Display all artists with 'William' somewhere in their real name");
            var foundArtistWilliam = from artist in Artists
                                     where artist.RealName.Contains("William")
                                     select artist;

            //select new {artist.RealName, artist.ArtistName, artist.Age};


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

            // Display all groups with names less than 8 characters in length.
            System.Console.WriteLine("");
            System.Console.WriteLine("Display all groups with names less than 8 characters in length.");

            var groupNameWithLessThan8Chars = Groups.Where(i => i.GroupName.Count() < 8);


            foreach (var i in groupNameWithLessThan8Chars)
            {
                System.Console.WriteLine(i.GroupName);
            }

            //Display the 3 oldest artist from Atlanta
            // var foundArtistFromAtlanta = from artist in Artists
            //                              orderby artist.Age descending
            //                              select new {artist.ArtistName, artist.Age};

            // foreach(var i in foundArtistFromAtlanta)
            // {
            //     System.Console.WriteLine(i);
            // }

            System.Console.WriteLine("");
            System.Console.WriteLine("Display the 3 oldest artist from Atlanta");

            IEnumerable <Artist> foundArtistFromAtlantaList = Artists.OrderByDescending(i => i.Age)
                                                              .Where(i => i.Hometown == "Atlanta")
                                                              .Take(3)
                                                              .ToList();

            foreach (var i in foundArtistFromAtlantaList)
            {
                System.Console.WriteLine(i.RealName + " " + i.Age);
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            // var groupnamesFromNewYorkCity = Groups.Join(Artists,
            //                                            gItem => gItem,
            //                                            aItem => aItem,
            //                                            (gItem, aItem) =>
            //                                            {
            //                                                 return gItem + " " + aItem;
            //                                            }).Where(aItem => aItem.Hometown == "New York City");
            System.Console.WriteLine("");
            System.Console.WriteLine("(Optional) Display the Group Name of all groups that have members that are not from New York City");
            var groupnamesFromNewYorkCityList = from g in Groups
                                                join a in Artists on g.Id equals a.GroupId
                                                where a.Hometown != "New York City"// && gGroup.Count() == 1
                                                group g by new { ggroupname = g.GroupName, gid = g.Id } into g select new{
                ggroupname = g.Key.ggroupname,
                gid        = g.Key.gid,
            };

            foreach (var i in groupnamesFromNewYorkCityList)
            {
                System.Console.WriteLine(i);
            }

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            System.Console.WriteLine("");
            System.Console.WriteLine("(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'");
            var ArtistNameOfGroup = from a in Artists
                                    join g in Groups on a.GroupId equals g.Id
                                    where g.GroupName == "Wu-Tang Clan"
                                    select new { a.ArtistName, g.GroupName };

            foreach (var i in ArtistNameOfGroup)
            {
                System.Console.WriteLine(i);
            }
        }
Esempio n. 7
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //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 newL = Artists.Where(s => s.Hometown == "Mount Vernon").Single();

            Console.WriteLine($"{newL.ArtistName} from Mt. Vernon is {newL.Age}");

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

            Console.WriteLine($"{young.ArtistName} is the youngest");

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

            foreach (Artist w in williams)
            {
                Console.WriteLine($"{w.RealName}");
            }
            //Display groups with names less than 8 characters in length
            List <Group> shorty = Groups.Where(n => n.GroupName.Length < 8).ToList();

            foreach (Group p in shorty)
            {
                Console.WriteLine($"{p.GroupName}");
            }
            //Display the 3 oldest artist from Atlanta
            List <Artist> atl = Artists.Where(x => x.Hometown == "Atlanta").OrderByDescending(y => y.Age).ToList();

            for (int i = 0; i < 3; i++)
            {
                Console.WriteLine($"{atl[i].RealName} is {atl[i].Age}");
            }
            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            List <Artist> notNY = Artists.Where(z => z.Hometown != "New York City").ToList();
            List <string> combo = notNY.Join(Groups, Art => Art.GroupId, Grou => Grou.Id, (Art, Grou) => { Art.Group = Grou; return(Art); }).Select(artist => artist.Group.GroupName).Distinct().ToList();

            foreach (string v in combo)
            {
                Console.WriteLine($"{v}");
            }
            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Group WuTang = Groups.Where(group => group.GroupName == "Wu-Tang Clan")
                           .GroupJoin(Artists,
                                      group => group.Id,
                                      artist => artist.GroupId,
                                      (group, artists) => { group.Members = artists.ToList(); return(group); })
                           .Single();

            Console.WriteLine("List of Artist in the Wu-Tang Clan:");
            foreach (var artist in WuTang.Members)
            {
                Console.WriteLine(artist.ArtistName);
            }
        }
Esempio n. 8
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //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> Result1 = Artists.Where(artist => artist.Hometown == "Mount Vernon").ToArray();

            Console.WriteLine("ARTIST FROM MOUNT VERNON:");
            foreach (var val in Result1)
            {
                Console.WriteLine("Artist from Mt. Vernon: {0}, Age: {1}", val.RealName, val.Age);
            }

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

            Console.WriteLine("YOUNGEST ARTIST:");
            Console.WriteLine("Name: {0}, Youngest Age: {1}.", Result2.RealName, Result2.Age);

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

            Console.WriteLine("ARTISTS WITH 'WILLIAM' IN REAL NAME:");
            foreach (var val in Result3)
            {
                Console.WriteLine("Name: {0}.", val.RealName);
            }

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

            Console.WriteLine("GROUP WITH GROUPNAMES OF LESS THAN 8 CHARACTERS:");

            foreach (var val in Result4)
            {
                Console.WriteLine("Group Name: {0}", val.GroupName);
            }

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

            Console.WriteLine("OLDEST ARTISTS FROM ATLANTA:");
            Console.WriteLine("Name: {0}, Age: {1}.", Result5[0].RealName, Result5[0].Age);
            Console.WriteLine("Name: {0}, Age: {1}.", Result5[1].RealName, Result5[1].Age);
            Console.WriteLine("Name: {0}, Age: {1}.", Result5[2].RealName, Result5[2].Age);

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            List <string> Result6 = Artists.Join(Groups,
                                                 artist => artist.GroupId,
                                                 group => group.Id,
                                                 (artist, group) => { artist.Group = group; return(artist); })
                                    .Where(artist => (artist.Hometown != "New York City" && artist.Group != null))
                                    .Select(artist => artist.Group.GroupName)
                                    .Distinct()
                                    .ToList();

            Console.WriteLine("DISPLAY GROUP NAME OF ALL GROUPS NOT FROM NY:");
            foreach (var group in Result6)
            {
                Console.WriteLine(group);
            }

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            List <Artist> Result7 = Artists.Join(Groups,
                                                 artist => artist.GroupId,
                                                 group => group.Id,
                                                 (artist, group) => { artist.Group = group; return(artist); })
                                    .Where(artist => (artist.Group.GroupName == "Wu-Tang Clan"))
                                    .ToList();

            Console.WriteLine("DISPLAY ARTISTS NAMES OF MEMBERS IN 'WU-TANG CLAN'");
            foreach (var val in Result7)
            {
                Console.WriteLine("Artist Name: {0}", val.RealName);
            }
        }
Esempio n. 9
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //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(artist => artist.Hometown == "Mount Vernon");

            foreach (var artist in mountVernonArtist)
            {
                System.Console.WriteLine("The one artist that lives in Mount Vernon: " + artist.ArtistName);
            }

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

            System.Console.WriteLine("The youngest artist of them all is " + yungVanessa.ArtistName);


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

            System.Console.WriteLine("Here are all the artists with 'William' somewhere in their name");
            foreach (var artist in WilliamsSearch)
            {
                System.Console.WriteLine(artist.ArtistName);
            }

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

            System.Console.WriteLine("Here are the three oldest artists in Atlanta:");
            foreach (var artist in AtlantaOldest)
            {
                System.Console.WriteLine(artist.ArtistName);
            }

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

            System.Console.WriteLine("Here are the groups with names less than 8 characters");
            foreach (var group in EightCharGroups)
            {
                System.Console.WriteLine(group.GroupName);
            }

            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            var NotNYers = Groups.Join(Artists, group => group.Id, artist => artist.GroupId, (group, artist) =>
            {
                if (artist.Hometown != "New York City")
                {
                    return(group.GroupName);
                }
                else
                {
                    return(null);
                }
            }).Distinct();

            System.Console.WriteLine("Here are the groups that don't contain New Yorkers in them");
            foreach (var groupname in NotNYers)
            {
                System.Console.WriteLine(groupname);
            }

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            var WuTangMembers = (from a in Artists
                                 join g in Groups on a.GroupId equals g.Id
                                 where a.GroupId == 100
                                 select a.ArtistName).ToList();

            if (WuTangMembers.Any())
            {
                System.Console.WriteLine("Here are all the members of the Wu Tang Clan");
                foreach (var person in WuTangMembers)
                {
                    System.Console.WriteLine(person);
                }
            }
            ;
        }
Esempio n. 10
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //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 FromMtVernon = Artists.Where(artist => artist.Hometown == "Mount Vernon").Single();

            Console.WriteLine($"The artist {FromMtVernon.ArtistName} from Mt Vernon is {FromMtVernon.Age} years old");
            //Who is the youngest artist in our collection of artists?
            Artist Youngest = Artists.OrderBy(artist => artist.Age).First();

            Console.WriteLine($"The Youngest artist is {Youngest.ArtistName}");
            //Display all artists with 'William' somewhere in their real name
            List <Artist> Williams = Artists.Where(artist => artist.RealName.Contains("William")).ToList();

            Console.WriteLine("The Following artists have William in their real names:");
            foreach (var artist in Williams)
            {
                Console.WriteLine(artist.ArtistName + " - " + artist.RealName);
            }

            //Display the names of all groups less than 8 characters in length
            List <Group> groupByLength = Groups.Where(group => group.GroupName.Length < 8).ToList();

            Console.WriteLine("All groups with names less than 8 in length:");
            foreach (var group in groupByLength)
            {
                Console.WriteLine(group.GroupName);
            }

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

            Console.WriteLine("The three oldest artists from Atlanta are:");
            foreach (var artist in Oldest)
            {
                Console.WriteLine(artist.ArtistName + " - " + artist.Age);
            }
            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            List <string> NonNewYorkGroups = Artists
                                             .Join(Groups, artist => artist.GroupId, group => group.Id, (artist, group) => { artist.Group = group; return(artist); })
                                             .Where(artist => (artist.Hometown != "New York City" && artist.Group != null))
                                             .Select(artist => artist.Group.GroupName)
                                             .Distinct()
                                             .ToList();

            Console.WriteLine("All groups with members not from New York City:");
            foreach (var group in NonNewYorkGroups)
            {
                Console.WriteLine(group);
            }

            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            Group WuTang = Groups.Where(group => group.GroupName == "Wu-Tang Clan")
                           .GroupJoin(Artists,
                                      group => group.Id,
                                      artist => artist.GroupId,
                                      (group, artists) => { group.Members = artists.ToList(); return(group); })
                           .Single();

            Console.WriteLine("List of Artist in the Wu-Tang Clan:");
            foreach (var artist in WuTang.Members)
            {
                Console.WriteLine(artist.ArtistName);
            }
        }
Esempio n. 11
0
        public static void Main(string[] args)
        {
            //Collections to work with
            List <Artist> Artists = JsonToFile <Artist> .ReadJson();

            List <Group> Groups = JsonToFile <Group> .ReadJson();

            //========================================================
            //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 vernon = Artists.Where(city => city.Hometown == "Mount Vernon").Select(p => new IEnumerable(p.RealName, p.Age));
            // System.Console.WriteLine(vernon.RealName + " " + vernon.Age);


            var artistfromVernon = from p in Artists
                                   where p.Hometown == "Mount Vernon"
                                   select p.RealName;

            System.Console.WriteLine(artistfromVernon);
            foreach (var art in artistfromVernon)
            {
                System.Console.WriteLine(art);
            }
            //Who is the youngest artist in our collection of artists?
            var youngestArt = (from y in Artists
                               // orderby y.Age ascending
                               select y.Age).Min();

            System.Console.WriteLine(youngestArt);
            // foreach( var yong in youngestArt){
            //     System.Console.WriteLine(yong);
            // }
            //Display all artists with 'William' somewhere in their real name
            var WilliamArtists = from a in Artists
                                 where a.RealName.Contains("William")
                                 select a.ArtistName;

            foreach (var billy in WilliamArtists)
            {
                Console.WriteLine($"Billies: {billy}");
            }

            //Display the 3 oldest artist from Atlanta
            var oldArt = (from a in Artists
                          orderby a.Age descending
                          where a.Hometown == "Atlanta"
                          select new { a.ArtistName, a.Age, a.Hometown }).Take(3);

            System.Console.WriteLine("-------------------------------------------------");
            foreach (var billy in oldArt)
            {
                Console.WriteLine($"{billy}");
            }
            //(Optional) Display the Group Name of all groups that have members that are not from New York City
            var nonNYC = (from g in Groups
                          join a in Artists on g.Id equals a.GroupId
                          where a.Hometown != "New York City"
                          select g.GroupName).Distinct();

            foreach (var group in nonNYC)
            {
                Console.WriteLine($"Groups: {group}");
            }
            //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'
            var WuTang = from a in Artists
                         join g in Groups on a.GroupId equals g.Id
                         where g.Id == 1
                         select a.ArtistName;

            foreach (var artist in WuTang)
            {
                Console.WriteLine($"Wutang Members: {artist}");
            }
            var shortName = from g in Groups
                            where g.GroupName.Count() < 8
                            select g.GroupName;

            foreach (var groups in shortName)
            {
                Console.WriteLine($"Short Names: {groups}");
            }
            Console.WriteLine(Groups.Count);
        }