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 MountName = from p in Artists where p.Hometown == "Mount Vernon" select new {p.ArtistName}; string[] MountName = Artists.Where(n => n.Hometown == "Mount Vernon").Select(n => new { n.ArtistName, n.Age }.ToString()).ToArray(); //Who is the youngest artist in our collection of artists? var YoungArtist = Artists.Min(n => n.Age); //Display all artists with 'William' somewhere in their real name var SameName = Artists.Where(name => name.ArtistName == "William"); //Display the 3 oldest artist from Atlanta string[] oldGuys = Artists.Join(Groups, (n => n.GroupId), (a => a.Id), (joinedArtist, joinedGroup) => { return($"{joinedArtist.ArtistName}, {joinedGroup.GroupName}"); }).ToArray(); var guyAtlanta = Artists.Where(h => h.Hometown == "Atlanta").OrderByDescending(h => h.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); Console.WriteLine(Artists.Count); Console.WriteLine("*******************************"); Console.WriteLine("*******************************"); Console.WriteLine("##################################################################"); }
public static void Main(string[] args) { //Collections to work with List <Artist> Artists = JsonToFile <Artist> .ReadJson(); List <Group> Groups = JsonToFile <Group> .ReadJson(); //There is only one artist in this collection from Mount Vernon, what is their name and age? Artist MV = Artists.Where(artist => artist.Hometown == "Mount Vernon").SingleOrDefault(); System.Console.WriteLine($"{MV.ArtistName}, {MV.Age}"); //Who is the youngest artist in our collection of artists? System.Console.WriteLine($"{Artists.Where( artist => artist.Age == Artists.Min( a => a.Age)).SingleOrDefault().ArtistName} is the youngest"); //Display all artists with 'William' somewhere in their real name List <Artist> williams = Artists.Where(artist => artist.RealName.Contains("William")).ToList(); foreach (Artist will in williams) { System.Console.WriteLine(will.ArtistName); } //Display the 3 oldest artist from Atlanta List <Artist> old = Artists.OrderByDescending(a => a.Age).Take(3).ToList(); // Take returns the first 3 from the query //(Optional) Display the Group Name of all groups that have members that are not from New York City List <Group> 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) .Distinct() .ToList(); //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' // Own try Console.WriteLine("----------------------------------"); List <Artist> artist_list = Artists.Where(artist => artist.Hometown.Contains("Los Angeles")).ToList(); foreach (Artist i in artist_list) { Console.WriteLine($"{i.ArtistName} - {i.Age}"); } }
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 mtVernonArtist = from guy in Artists where guy.Hometown == "Mount Vernon" select new {guy.ArtistName , guy.Age }; // foreach (var buddy in mtVernonArtist){ // Console.WriteLine(buddy); // } //Who is the youngest artist in our collection of artists? // var youngList = from youngin in Artists orderby youngin.Age ascending select new {youngin.ArtistName, youngin.Age}; // foreach (var findingYoungest in youngList){ // Console.WriteLine(findingYoungest); // break; // } // Console.WriteLine(youngList.First()); //Display all artists with 'William' somewhere in their real name // var will = from bill in Artists // where bill.RealName.Contains("William") // select new {bill.ArtistName, bill.RealName, bill.Age}; // foreach (var buddy in will){ // Console.WriteLine(buddy); // } //Display the 3 oldest artist from Atlanta // var oldHeads = from geizer in Artists orderby geizer.Age descending // select new {geizer.ArtistName, geizer.Age, geizer.RealName}; // foreach (var buddah in oldHeads.Take(3)){ // Console.WriteLine(buddah); // } //(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' }
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 artist = from match in Artists where match.Hometown == "Mount Vernon" select new { match.ArtistName, match.Age }; foreach (var item in artist) { Console.WriteLine(item); } //Who is the youngest artist in our collection of artists? Artist YoungestArtist = Artists.OrderBy(youngestArtist => youngestArtist.Age) .First(); Console.WriteLine(YoungestArtist.RealName); //Display all artists with 'William' somewhere in their real name List <Artist> NamesWithWilliam = Artists.Where(myArtist => myArtist.RealName.Contains("William")).ToList(); foreach (var user in NamesWithWilliam) { Console.WriteLine(user.RealName); } //Display the 3 oldest artist from Atlanta List <Artist> OldestArtists = Artists.OrderByDescending(myArtist => myArtist.Age) .Take(3).ToList(); foreach (var myArtist in OldestArtists) { Console.WriteLine(myArtist.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' }
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 YoungestAr = Artists.OrderBy(artist => artist.Age).First(); System.Console.WriteLine($"{YoungestAr.ArtistName} is the youngest artist, and his age is {YoungestAr.Age}"); //Display all artists with 'William' somewhere in their real name List <Artist> ContainsWill = Artists.Where(artist => artist.RealName.Contains("William")).ToList(); foreach (var x in ContainsWill) { System.Console.WriteLine(x.ArtistName + "" + x.RealName); } //Display the 3 oldest artist from Atlanta List <Artist> OldestFromAtlanta = Artists.Where(artist => artist.Hometown == "Atlanta") .OrderByDescending(artist => artist.Age) .Take(3) .ToList(); foreach (var x in OldestFromAtlanta) { System.Console.WriteLine(x.ArtistName + ", " + x.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' }
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 mountVernon = Artists.First(a => a.Hometown == "Mount Vernon"); System.Console.WriteLine(mountVernon); //Who is the youngest artist in our collection of artists? var youngest = Artists.Min(a => a.Age); var artist = Artists.Where(a => a.Age == youngest); System.Console.WriteLine(artist.FirstOrDefault().ArtistName + " is " + youngest + " years old."); //Display all artists with 'William' somewhere in their real name IEnumerable <Artist> williams = Artists.Where(a => a.RealName.Contains("William")); foreach (Artist x in williams) { System.Console.WriteLine(x.RealName); } //Display the 3 oldest artist from Atlanta IEnumerable <Artist> old = Artists.Where(a => a.Hometown == "Atlanta").OrderBy(a => a.Age).Take(3); foreach (Artist x in old) { System.Console.WriteLine(x); } //(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 = 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 results = from Artist in Artists where Artist.Hometown.Contains("Mount Vernon") select Artist; // foreach(var artist in results){ // Console.WriteLine(artist.ArtistName); // } // //Who is the youngest artist in our collection of artists? // var youngest = Artists.OrderBy(x => x.Age).FirstOrDefault(); // System.Console.WriteLine(youngest.ArtistName+" Age:"+ youngest.Age); // //Display all artists with 'William' somewhere in their real name // var people = from Artist in Artists where Artist.RealName.Contains("William") select Artist; // foreach(var artist in people){ // Console.WriteLine(artist.ArtistName); // } //Display all groups with names less than 8 characters in length // var shortNames = from Artist in Artists where Artist.ArtistName.Length < 8 select Artist; // foreach(var artist in shortNames){ // Console.WriteLine(artist.ArtistName); // } //Display the 3 oldest artist from Atlanta var oldestArtists = Artists.OrderByDescending(x => x.Age).Take(3); foreach (var artist in oldestArtists) { Console.WriteLine(artist.ArtistName + " Age:" + artist.Age); } }
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 Vernon = Artists.Where(artist => artist.Hometown == "Mount Vernon").First(); Console.WriteLine(Vernon.ArtistName); Console.WriteLine(); //Who is the youngest artist in our collection of artists? Artist Youngest = Artists.OrderBy(artist => artist.Age).First(); Console.WriteLine(Youngest.ArtistName); Console.WriteLine(); //Display all artists with 'William' somewhere in their real name var Wills = Artists.Where(artist => artist.RealName.Contains("William")); listPrint(Wills); Console.WriteLine(); //Display the 3 oldest artist from Atlanta var OldAtlanta = Artists.Where(artist => artist.Hometown == "Atlanta").OrderByDescending(artist => artist.Age).Take(3); listPrint(OldAtlanta); Console.WriteLine(); //(Optional) Display the Group Name of all groups that have members that are not from New York City var NotYork = Groups.Join(Artists.Where(artist => artist.Hometown != "New York City"), group => group.Id, artist => artist.GroupId, (group, artist) => { return(group); }).Distinct(); listPrint(NotYork); Console.WriteLine(); //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' var WTC = Artists.Join(Groups.Where(group => group.GroupName == "Wu-Tang Clan"), artist => artist.GroupId, group => group.Id, (artist, group) => { return(artist); }); listPrint(WTC); }
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 mtVernonHome = from artist in Artists where artist.Hometown == "Mount Vernon" select artist; System.Console.WriteLine(mtVernonHome); //Who is the youngest artist in our collection of artists? string youngest = Artists.OrderBy(a => a.Age).First().ArtistName; System.Console.WriteLine(youngest); // var youngest = from art in Artists orderby art.Age select art; // System.Console.WriteLine(youngest); //Display all artists with 'William' somewhere in their real name IEnumerable <Artist> realWiliams = Artists.Where(artist => artist.RealName.Contains("William")); foreach (Artist a in realWiliams) { System.Console.WriteLine(a.RealName); } //Display the 3 oldest artist from Atlanta IEnumerable <Artist> atlantaDudes = Artists.OrderByDescending(a => a.Age).Where(artist => artist.Hometown == "Atlanta").Take(3); foreach (Artist b in atlantaDudes) { System.Console.WriteLine(b.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' }
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 fromMountVernon = Artists.Where(artist => artist.Hometown == "Mount Vernon").ToList(); foreach (var artist in fromMountVernon) { System.Console.WriteLine(artist.RealName); System.Console.WriteLine(artist.Age); } //Who is the youngest artist in our collection of artists? var youngestArtist = Artists.OrderBy(artist => artist.Age).FirstOrDefault(); System.Console.WriteLine(youngestArtist.RealName); //Display all artists with 'William' somewhere in their real name var containsWilliam = Artists.Where(artist => artist.RealName.Contains("William")).ToList(); foreach (var artist in containsWilliam) { System.Console.WriteLine(artist.RealName); } //Display the 3 oldest artist from Atlanta var oldestInAtlanta = Artists.Where(artist => artist.Hometown == "Atlanta").OrderByDescending(artist => artist.Age).Take(3).ToList(); foreach (var artist in oldestInAtlanta) { System.Console.WriteLine($"{artist.ArtistName} {artist.Age}"); } //Display the group name of all groups that have members that are not from New York City var notFromNewYork = Group. // Display the artist names of all members in the group Wu-Tang Clan }
public static void Main(string[] args) { //Collections to work with List <Artist> Artists = JsonToFile <Artist> .ReadJson(); List <Group> Groups = JsonToFile <Group> .ReadJson(); //There is only one artist in this collection from Mount Vernon, what is their name and age? IEnumerable <Artist> theOne = Artists.Where(a => a.Hometown == "Mount Vernon"); //Who is the youngest artist in our collection of artists? IEnumerable <Artist> theOnly = Artists.OrderBy(b => b.Age); //Display all artists with 'William' somewhere in their real name IEnumerable <Artist> allW = Artists.Where(c => c.ArtistName == "William"); //Display all groups with names less than 8 characters in length IEnumerable <Group> allGroups = Groups.Where(d => d.GroupName.Length < 8).OrderBy(d => d.GroupName.Length); //Display the 3 oldest artists from Atlanta IEnumerable <Artist> oldestArtists = Artists.Where(e => e.Hometown == "Atlanta").OrderByDescending(e => e.Age).Take(3); //(Optional) Display the Group Name of all groups that have members that are not from New York City IEnumerable <Group> notYork = Groups.Join(Artists.Where(f => f.Hometown != "New York City"), group => group.Id, f => f.GroupId, (group, f) => { return(group); }).Distinct(); //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' IEnumerable <Artist> notWu = Artists.Join(Groups.Where(group => group.GroupName == "Wu-Tang Clan"), artist => artist.GroupId, group => group.Id, (artist, group) => { return(artist); }); //======================================================== //Solve all of the prompts below using various LINQ queries //======================================================== }
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 selectArtist = Artists.SingleOrDefault(art => art.Hometown == "Mount Vernon"); Console.WriteLine(selectArtist.Age); //Who is the youngest artist in our collection of artists? int youngestage = Artists.Min(art => art.Age); List <Artist> youngestArtist = Artists.Where(a => a.Age == youngestage).ToList(); System.Console.WriteLine(youngestArtist[0].ArtistName); //Display all artists with 'William' somewhere in their real name List <Artist> willArtists = Artists.Where(a => a.RealName.Contains("William")).ToList(); for (var i = 0; i < willArtists.Count; i++) { Console.WriteLine(willArtists[i].RealName); } //Display the 3 oldest artist from Atlanta List <Artist> oldestArtists = Artists.OrderByDescending(a => a.Age).ToList(); for (var i = 0; i < 3; i++) { Console.WriteLine(oldestArtists[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' }
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 fromMT = Artist.Where(Artist => Artist.Hometown == "mount Vernon").Single(); Console.WriteLine("The artist from {Artist.Hometown} is {fromMT.ArtistName}"); //Who is the youngest artist in our collection of artists? Artist young = Artist.OrderBy(Artist => Artist.age).First(); //Display all artists with 'William' somewhere in their real name List<Artist> will = Artist.Where(Artist => Artist.RealName.Contains("William")).ToList(); //Display the 3 oldest artist from Atlanta List<Artist> fromAT = Artist.Where(artist => artist.Hometown == "Atlanta") .OrderByDescending(artist => artist.age) .Take(3) .ToList(); //display all groups with 8 characters of less List<Group> less8 = Group.Where(Group => Group.GroupName.Length() > 8).ToList(); //(Optional) Display the Group Name of all groups that have members that are not from New York City List<Group> notNY = Group.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) .Disctinct() .ToList(); //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' }
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? //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' }
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 mountVernonArtist = from person in Artists where person.Hometown == "Mount Vernon" select new { person.ArtistName, person.Age }; System.Console.WriteLine(mountVernonArtist); //Who is the youngest artist in our collection of artists? var youngest = from young in Artists orderby young.Age ascending select Artists.First(); //Display all artists with 'William' somewhere in their real name var williams = Artists.Where(n => n.RealName.Contains("William")); //Display the 3 oldest artist from Atlanta var oldAtl = from emcees in Artists where emcees.Hometown == "Atlanta" orderby emcees.Age descending select Artists.Take(3); //(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' }
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> MountVernon = Artists.Where(artist => artist.Hometown == "Mount Vernon"); //Who is the youngest artist in our collection of artists? IEnumerable <Artist> YoungOne = Artists.Where(artist => artist.Age == Artists.Min(age => age.Age)); //Display all artists with 'William' somewhere in their real name IEnumerable <Artist> Williams = Artists.Where(artist => artist.RealName.Contains("William")); //Display the 3 oldest artist from Atlanta IEnumerable <Artist> OldiesAtlanta = Artists.Where(artist => artist.Hometown == "Atlanta").OrderBy(age => age.Age).Take(3); //Display all groups with names less than 8 characters in length IEnumerable <Group> GroupsWithLessThan8 = Groups.Where(groups => groups.GroupName.Length < 8); //(Optional) Display the Group Name of all groups that have members that are not from New York City var NYsucks = Groups.Join(Artists, groups => groups.Id, artist => artist.GroupId, (groups, artist) => { if (artist.Hometown != "New York City") { return(groups.GroupName); } else { return(null); } }).Distinct(); //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' }
public static void Main(string[] args) { List <Artist> Artists = JsonToFile <Artist> .ReadJson(); List <Group> Groups = JsonToFile <Group> .ReadJson(); const String KEY = "William"; //======================================================== //Solved 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> found = Artists.Where(artist => artist.Hometown == KEY); foreach (Artist i in found) { Console.WriteLine("Match found for hometown {0} - {1}", KEY, i.Hometown.ToString()); } //Who is the youngest artist in our collection of artists? Artist youngest = (from match in Artists orderby match.Age ascending select match).First(); Console.WriteLine("Youngest at {0} is {1}", youngest.Age, youngest.ArtistName); //Display all artists with 'William' somewhere in their real name IEnumerable <Artist> matches = Artists.Where(match => match.RealName.Contains(KEY)); foreach (Artist i in matches) { Console.WriteLine("Match found for real name {0} - {1}", KEY, i.RealName); } //Display the 3 oldest artist from Atlanta IEnumerable <Artist> //(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' }
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 artist = Artists.FirstOrDefault(a => a.Hometown == "Mount Vernon"); Console.WriteLine("Artist from Mount Vernon's name is {0} and age is {1}", artist.RealName, artist.Age); //Who is the youngest artist in our collection of artists? artist = Artists.FirstOrDefault(a => a.Age == Artists.Min(x => x.Age)); Console.WriteLine("The youngest artist is {0}", artist.RealName); //Display all artists with 'William' somewhere in their real name IEnumerable <Artist> allArtists = Artists.FindAll(a => a.RealName.Contains("William")); foreach (Artist elem in allArtists) { Console.WriteLine("The artists name is {0}", elem.RealName); } // Display all groups with names less than 8 characters in length. foreach (Group elem in Groups.Where(g => g.GroupName.Length < 8)) { Console.WriteLine("The groups name has less than eigth characters {0} ", elem.GroupName); } //Display the 3 oldest artist from Atlanta allArtists = Artists.OrderByDescending(a => a.Age).Where(c => c.Hometown == "Atlanta").Take(3); foreach (Artist elem in allArtists) { Console.WriteLine("The old artists name is {0}", elem.RealName); } //(Optional) Display the Group Name of all groups that have members that are not from New York City IEnumerable <Group> groups = from g in Groups join a in Artists on g.Id equals a.GroupId where !( from a2 in Artists where a2.Hometown == "New York City" select a2.GroupId) .Contains(g.Id) select g; foreach (Group elem in groups.Distinct()) { Console.WriteLine("This group does not have members from NYC: {0}", elem.GroupName); } //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' IEnumerable <Artist> artists = from a in Artists join g in Groups on a.GroupId equals g.Id where g.GroupName == "Wu-Tang Clan" select a; foreach (Artist a in artists.Distinct()) { Console.WriteLine("This artists is in Wu Tang Clan: {0}", a.ArtistName); } }
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(Artists); //======================================================== //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 mvartist = Artists.Where(a => a.Hometown == "Mount Vernon"); foreach (var item in mvartist) { System.Console.WriteLine(item.RealName); System.Console.WriteLine(item.Age); } //Who is the youngest artist in our collection of artists? var young = Artists.OrderByDescending(a => a.Age).Last(); System.Console.WriteLine(young.Age); System.Console.WriteLine(young.RealName); //Display all artists with 'William' somewhere in their real name var willy = Artists.Where(a => a.RealName.Contains("William")); foreach (var art in willy) { System.Console.WriteLine(art.RealName); } //Display the 3 oldest artist from Atlanta var old = Artists.OrderByDescending(a => a.Age).Where(b => b.Hometown == "Atlanta").Take(3); foreach (var i in old) { System.Console.WriteLine(i.ArtistName + " is old!"); System.Console.WriteLine(i.Age); } // (Optional) Display the Group Name of all groups that have members that are not from New York City var nyc = (from g in Groups join a in Artists on g.Id equals a.GroupId where (a.Hometown != "New York City") select new { g.GroupName }).Distinct(); // var nyc = nyc.Select(x=> x.GroupName).Distinct(); foreach (var i in nyc) { System.Console.WriteLine(i.GroupName); } //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' var wtc = from g in Groups join a in Artists on g.Id equals a.GroupId select new { gName = g.GroupName, aName = a.ArtistName }; foreach (var i in wtc) { if (i.gName == "Wu-Tang Clan") { System.Console.WriteLine(i.aName + " is in Wu-Tang Clan"); } } }
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? //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' IEnumerable <Artist> mountVernon = from town in Artists where town.Hometown == "Mount Vernon" orderby town select town; foreach (Artist info in mountVernon) { Console.WriteLine("The artist from Mount Vernon is " + info.ArtistName + ", and he is " + info.Age + " years old."); } // IEnumerable<Artist> youngest = // from age in Artists // orderby age.Age // select age; // foreach (Artist info in youngest){ // Console.WriteLine(info.ArtistName + ", " + info.Age + " years old."); // } // Console.WriteLine(youngest.Age); Artist youngest = Artists.OrderBy(young => young.Age).First(); Console.WriteLine("The youngest artist is " + youngest.ArtistName + ", who is " + youngest.Age + " years old."); List <Artist> williams = Artists.Where(name => name.RealName.Contains("William")).ToList(); Console.WriteLine("The artists with William in their real name are:"); foreach (Artist william in williams) { Console.WriteLine(william.ArtistName + " : " + william.RealName); } List <Group> LessThan8 = Groups.Where(name => name.GroupName.Length < 8).ToList(); Console.WriteLine("The groups with names that have less than 8 characters are:"); foreach (Group group in LessThan8) { Console.WriteLine(group.GroupName); } List <Artist> oldestATL = Artists.Where(old => old.Hometown == "Atlanta").ToList().OrderByDescending(artist => artist.Age).ToList(); Console.WriteLine("The oldest artists from Atlanta are:"); Console.WriteLine(oldestATL[0].ArtistName); Console.WriteLine(oldestATL[1].ArtistName); Console.WriteLine(oldestATL[2].ArtistName); }
public static void Main(string[] args) { { List <Artist> Artists = JsonToFile <Artist> .ReadJson(); List <Group> Groups = JsonToFile <Group> .ReadJson(); // There is only one artist in this collection from Mount Vernon, what is their name and age? var artistMV = from artist in Artists where artist.Hometown == "Mount Vernon" select artist; Console.WriteLine("The only artist from Mount Vernon:"); foreach (var artist in artistMV) { Console.WriteLine("Name: " + artist.RealName + " - Age: " + artist.Age); } Console.WriteLine(" "); Console.WriteLine("---"); Console.WriteLine(" "); // Who is the youngest artist in our collection of artists? var artistYoung = from artist in Artists select artist; Artist youngestArtist = Artists.First(); foreach (var artist in artistYoung) { if (artist.Age < youngestArtist.Age) { youngestArtist = artist; } } Console.WriteLine("The youngest artist is: " + youngestArtist.ArtistName); Console.WriteLine(" "); Console.WriteLine("---"); Console.WriteLine(" "); // Display all artists with 'William' somewhere in their real name var artistWill = from artist in Artists select artist; Console.WriteLine("All artists with 'William' somewhere in their real name:"); foreach (var artist in artistWill) { if (artist.RealName.Contains("William")) { Console.WriteLine(artist.ArtistName + " - Real Name: " + artist.RealName); } } Console.WriteLine(" "); Console.WriteLine("---"); Console.WriteLine(" "); // Display all groups with names less than 8 characters in length var artistShortName = from artist in Artists select artist; Console.WriteLine("Groups with names less than 8 characters in length:"); foreach (var artist in artistShortName) { if (artist.ArtistName.Length < 8) { Console.WriteLine(artist.ArtistName); } } Console.WriteLine(" "); Console.WriteLine("---"); Console.WriteLine(" "); // Display the 3 oldest artists from Atlanta var artistOldest = from artist in Artists where artist.Hometown == "Atlanta" orderby artist.Age descending select artist; Console.WriteLine("The three oldest artists from Atlanta:"); int i = 1; foreach (var artist in artistOldest) { if (i <= 3) { Console.WriteLine(artist.ArtistName + " - Age: " + artist.Age); } else { break; } i++; } Console.WriteLine(" "); Console.WriteLine("---"); Console.WriteLine(" "); } }
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 //======================================================== Console.WriteLine("There is only one artist in this collection from Mount Vernon, what is their name and age?"); var findArtist = from artist in Artists where artist.Hometown == "Mount Vernon" select new { name = artist.ArtistName, age = artist.Age }; foreach (var artist in findArtist) { Console.WriteLine($"{artist.name}, {artist.age}"); } Console.WriteLine("Who is the youngest artist in our collection of artists?"); var youngest = (from artist in Artists orderby artist.Age ascending select artist.ArtistName).First(); Console.WriteLine($"{youngest}"); Console.WriteLine("Display all artists with 'William' somewhere in their real name"); var realName = Artists.Where(name => name.RealName.Contains("William")); foreach (var artist in realName) { Console.WriteLine($"{artist.RealName}"); } Console.WriteLine("Display the 3 oldest artist from Atlanta"); var oldest = Artists.Where(artist => artist.Hometown == "Atlanta").OrderByDescending(artist => artist.Age).Take(3); foreach (var artist in oldest) { Console.WriteLine($"{artist.ArtistName}"); } Console.WriteLine("(Optional) Display the Group Name of all groups that have members that are not from New York City"); var nonNew = Artists.Where(a => a.Hometown != "New York City").Join(Groups, a => a.GroupId, g => g.Id, (a, g) => new { g.GroupName }).Distinct(); foreach (var group in nonNew) { Console.WriteLine($"{group.GroupName}"); } Console.WriteLine("(Optional) Display the artist names of all members of the group 'Wu-Tang Clan'"); var clan = Groups.Where(g => g.GroupName == "Wu-Tang Clan").Join(Artists, g => g.Id, a => a.GroupId, (g, a) => new { a.ArtistName }); foreach (var artist in clan) { Console.WriteLine($"{artist.ArtistName}"); } Console.WriteLine(Groups.Count); }
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}, {FromMtVernon.Age}"); //Who is the youngest artist in our collection of artists? Artist youngest = Artists.OrderBy(artist => artist.Age).First(); Console.WriteLine($"the youngest Artist:{youngest.ArtistName}, {youngest.Age}"); //Display all artists with 'William' somewhere in their real name List <Artist> ContWilliams = Artists.Where(artist => artist.RealName.Contains("William")).ToList(); Console.WriteLine("All Williams:"); foreach (var artist in ContWilliams) { Console.WriteLine(artist.ArtistName + artist.RealName); } //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("3 oldest artist:"); 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> NotInNewYork = 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("Groups that are not From New York"); foreach (var group in NotInNewYork) { Console.WriteLine(group); } //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' Group WuTangClan = 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("Artist members of the Wu-Tang Clan:"); foreach (var artist in WuTangClan.Members) { Console.WriteLine(artist.ArtistName); } }
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> artVern = Artists.Where(str => str.Hometown == "Mount Vernon"); foreach (var art in artVern) { Console.WriteLine(art.ArtistName + "--art"); } //Who is the youngest artist in our collection of artists? Artist youngest = new Artist(); Console.WriteLine(youngest.Age + "--youngest"); foreach (var young in Artists) { if (youngest.Age == 0) { youngest = young; } else { youngest = (youngest.Age < young.Age ? youngest : young); } } Console.WriteLine(youngest.ArtistName + ": " + youngest.Age); //Display all artists with 'William' somewhere in their real name IEnumerable <Artist> will = Artists.Where(str => str.RealName.IndexOf("William") > 0); foreach (var william in will) { Console.WriteLine(william.RealName + "--" + william.ArtistName); } // Display the 3 oldest artist from Atlanta // select top 3 artists from atlanta orderby artist age desc. IEnumerable <Artist> oldest = Artists.Where(old => old.Hometown == "Atlanta").OrderByDescending(old => old.Age).Take(3); foreach (var oldArtist in oldest) { Console.WriteLine(oldArtist.ArtistName + ":" + oldArtist.Hometown + ":" + oldArtist.Age); } //(Optional) Display the Group Name of all groups that have members that are not from New York City var nonyc = Groups.Join(Artists.Where(notny => notny.Hometown != "New York City"), group => group.Id, artist => artist.GroupId, (group, artist) => { return(group); }).Distinct(); PrintLine(nonyc); //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' // select wutang from groups then select all members from var wutang = Artists.Join(Groups.Where(grp => grp.GroupName == "Wu-Tang Clan"), art => art.GroupId, group => group.Id, (art, grp) => { return(art); }); }
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 mount = from artist in Artists where artist.Hometown == "Mount Vernon" select artist; Console.WriteLine(mount); foreach (var i in mount) { Console.WriteLine(i.ArtistName + " is " + i.Age); } Artists.Where(h => h.Hometown == "Mount Vernon"); //Who is the youngest artist in our collection of artists? var youngest = Artists.Min(x => x.Age); var youngest1 = from artist in Artists where artist.Age == Artists.Min(x => x.Age) select new { artist.ArtistName, artist.Age }; Console.WriteLine(youngest1); foreach (var i in youngest1) { Console.WriteLine(i.ArtistName + " is " + i.Age); } Artists.Where(a => a.Age == Artists.Min(x => x.Age)); //Display all artists with 'William' somewhere in their real name var name = from artist in Artists where artist.RealName.Contains("William") select new { artist.ArtistName, artist.RealName }; foreach (var c in name) { Console.WriteLine(c.ArtistName + "--" + c.RealName); } Artists.Where(a => a.RealName.Contains("William")); //Display the 3 oldest artist from Atlanta var oldest = (from artist in Artists orderby artist.Age descending select new { artist.ArtistName, artist.Age }).Take(3); foreach (var c in oldest) { Console.WriteLine(c.ArtistName + " is " + c.Age); } Artists.OrderByDescending(a => a.Age).Take(3); //(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 = 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); } }
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 results = from Artist in Artists where Artist.Hometown.Contains("Mount Vernon") select Artist; // foreach (var artist in results) // { // Console.WriteLine($"The artist is {artist.Age}. This artist is {artist.ArtistName}."); // } //Who is the youngest artist in our collection of artists? // var youngest = Artists.OrderBy(x => x.Age).FirstOrDefault(); // System.Console.WriteLine($"This artist is {youngest.ArtistName}, and he is {youngest.Age}."); //Display all artists with 'William' somewhere in their real name // IEnumerable<Artist> Willy = Artists.Where(artist => artist.RealName.Contains("William")); // foreach (var artist in Willy) // { // Console.WriteLine($"{artist.ArtistName}"); // } // List<Artist> Williams = Artists.Where(artist => artist.RealName.Contains("William")).ToList(); // Console.WriteLine("============================="); // foreach (var artist in Williams) // { // Console.WriteLine(artist.ArtistName + " - " + artist.RealName); // } // var billy = from Artist in Artists where Artist.RealName.Contains("William") select Artist; // foreach (var artist in billy) // { // Console.WriteLine(artist.ArtistName); // } //Display the 3 oldest artist from Atlanta // IEnumerable<Artist> atlanta = Artists.OrderByDescending(x => x.Age).Take(3); // foreach (var artist in atlanta) // { // Console.WriteLine($"{artist.ArtistName} is the oldest artist."); // } // var atlanta = Artists.OrderByDescending(x => x.Age).Take(3); // foreach (var artist in atlanta) // { // Console.WriteLine($"These oldest artists is" +" " +artist.ArtistName); // } //(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' var Wu = Groups.Where(x => x.GroupName == "Wu-Tang Clan") .GroupJoin(Artists, x => x.Id, artist => artist.GroupId, (x, artists) => { x.Members = artists.ToList(); return(x); }) .Single(); Console.WriteLine("==============================================="); foreach (var artist in Wu.Members) { Console.WriteLine(artist.ArtistName); } }
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 first = from artist in Artists where artist.Hometown == "Mount Vernon" select new { artist.ArtistName, artist.Age }; Console.WriteLine(first); foreach (var c in first) { Console.WriteLine(c.ArtistName + " " + c.Age); } Artists.Where(h => h.Hometown == "Mount Vernon").SingleOrDefault(); //Who is the youngest artist in our collection of artists? var youngest = Artists.Min(x => x.Age); var youngest1 = from artist in Artists where artist.Age == Artists.Min(x => x.Age) select new { artist.ArtistName, artist.Age }; Console.WriteLine(youngest1); foreach (var c in youngest1) { Console.WriteLine(c.ArtistName + " " + c.Age); } Artists.Where(a => a.Age == Artists.Min(x => x.Age)).SingleOrDefault(); //Display all artists with 'William' somewhere in their real name var Will_realname = from artist in Artists where artist.RealName.Contains("William") select new { artist.ArtistName, artist.RealName }; foreach (var c in Will_realname) { Console.WriteLine(c.ArtistName + "--" + c.RealName); } Artists.Where(a => a.RealName.Contains("William")); //Display the 3 oldest artist from Atlanta var oldest = (from artist in Artists orderby artist.Age descending select new { artist.ArtistName, artist.Age }).Take(3); foreach (var c in oldest) { Console.WriteLine(c.ArtistName + " " + c.Age); } Artists.OrderByDescending(a => a.Age).Take(3); // Display all groups with names less than 8 characters in length. Groups.Where(g => g.GroupName.Length < 8); //(Optional) Display the Group Name of all groups that have members that are not from New York City (Artists.Where(a => a.Hometown != "New York City")).Join(Groups, aId => aId.GroupId, gId => gId.Id, (aId, gId) => { return($"{aId.ArtistName} from {gId.GroupName} "); }); //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' (Groups.Where(g => g.GroupName == "Wu-Tang Clan")).Join(Artists, gId => gId.Id, aId => aId.GroupId, (gId, aId) => { return($"{aId.ArtistName} from {gId.GroupName}"); }); }
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 one_artist = from match in Artists where match.Hometown == "Mount Vernon" select new { match.ArtistName, match.Age }; Console.WriteLine(one_artist.ToArray()[0]); //Who is the youngest artist in our collection of artists? // var youngest = from match in Artists // where match.Age < 24 // select new {match}; // Console.WriteLine(youngest.ToArray()[0].match.ArtistName); Artist youngest = Artists.OrderBy(artist => artist.Age).First(); Console.WriteLine(youngest.ArtistName); //Display all artists with 'William' somewhere in their real name IEnumerable <Artist> williams = Artists.Where(x => x.RealName.Contains("William")); Console.WriteLine("The artists with the name William are:"); for (int i = 0; i < williams.Count(); i++) { Console.WriteLine($"{i+1}. {williams.ToArray()[i].RealName}"); } //Display the 3 oldest artist from Atlanta IEnumerable <Artist> atlantans = Artists.Where(x => x.Hometown == "Atlanta").OrderByDescending(x => x.Age); int end = (atlantans.Count() > 3) ? end = 3 : end = atlantans.Count(); Console.WriteLine("The oldest Atlantans are:"); for (int i = 0; i < end; i++) { Console.WriteLine($"{i+1}. {atlantans.ToArray()[i].RealName} ({atlantans.ToArray()[i].Age})"); } //(Optional) Display the Group Name of all groups that have members that are not from New York City //Seems like busy work to me... //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' Group wuTangClan = Groups.Where( x => x.GroupName == "Wu-Tang Clan" ).GroupJoin( Artists, x => x.Id, y => y.GroupId, (x, z) => { x.Members = z.ToList(); return(x); } ).First(); Console.WriteLine("The artists in the Wu-Tang-Clan"); foreach (Artist artist in wuTangClan.Members) { Console.WriteLine($"{artist.ArtistName}"); } }
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? // Standard: // var res=from a in Artists // where a.Hometown == "Mount Vernon" // select new{a.ArtistName,a.Age}; // Chaining: // var res = Artists.Where(a=>a.Hometown == "Mount Vernon").Select(x=>new{x.ArtistName,x.Age}); //Who is the youngest artist in our collection of artists? // var res = Artists.Select(a=>new{a.ArtistName,a.Age}) // .Min(a=>a.Age); //Display all artists with 'William' somewhere in their real name // var res = from artist in Artists // where artist.RealName.Contains("William") // select artist.RealName; //Display the 3 oldest artist from Atlanta // This took like an hour to figure out // var res = Artists.Select(a=>new{a.ArtistName,a.Age,a.Hometown}) // .Where(x=>x.Hometown=="Atlanta") // .OrderByDescending(x=>x.Age) // .Take(3); //(Optional) Display the Group Name of all groups that have members that are not from New York City // var res = Groups.Join( // Artists.Where(x=>x.Hometown != "New York City"), // g=>g.Id, // a=>a.GroupId, // (g,a)=>{ // return g.GroupName; // } // ); //(Optional) Display the artist names of all members of the group 'Wu-Tang Clan' // Left Join // var res = Artists.Join( // Groups.Where(x=>x.GroupName == "Wu-Tang Clan"), // a=>a.GroupId, // g=>g.Id, // (a,g)=>{ // return a.ArtistName; // } // ); }