Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- //Za koriscenje LINQ potrebno je koristiti System.Linq namespace
- 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"},
- };
- //Trazimo autore koji rade u DressCode-u
- var result = from s in list
- where s.workPlace == "DressCode"
- select s.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