Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- using System.Collections.Generic;
- public class Program
- {
- public class Person{
- public string firstName,lastName;
- }
- public class PersonAndWork{
- public Person person;
- public string workPlace;
- }
- public static void Main()
- {
- List<PersonAndWork> list = new List<PersonAndWork>(){
- new PersonAndWork(){person = new Person(){firstName = "Elon", lastName = "Musk"}, workPlace = "Tesla"},
- new PersonAndWork(){person = new Person(){firstName = "Larry", lastName = "Page"}, workPlace = "Alphabet"},
- new PersonAndWork(){person = new Person(){firstName = "Satya", lastName = "Nadella"}, workPlace = "Microsoft"},
- new PersonAndWork(){person = new Person(){firstName = "Petar", lastName = "Petrovic"}, workPlace = "DressCode"},
- new PersonAndWork(){person = new Person(){firstName = "Petra", lastName = "Jovanovic"}, workPlace = "DressCode"},
- };
- var result = list.Where(x => x.workPlace == "DressCode").Select(x=> x.person);
- //Na ekranu ce se ispisati Petar Petrovic i Petra Jovanovic
- foreach(var author in result)
- Console.WriteLine($"{author.firstName} {author.lastName}");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement