Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Zadanie musi zostać rozwiązane za pomocą LINQ.
- Stwórz tablicę cities – zawierającą zadeklarowane przykładowe miasta ( częsć miast małą literą).
- Wypisz na konsole wszystkie miasta , które mają długość większą niż 4 ( Stringa) , wypisz miasta
- jako upperCase.
- Zdefiniuj klasę City , która posiada getter , konstruktory przechowuje następujące informację:
- -name
- -country
- -population
- Zdefiniuj Listę , która zawiera co najmniej 10 miast. Wypisz na ekeran wszystkie miasta , które
- mają liczbę ludności większą niż 100 000.
- Zdefinuj klasę Person z następującymi danymi :
- firstName
- lastName
- Age
- Zdefinuj odpowiedni konstruktor.
- Stwórz listę osób zawierającą co najmniej 10 osób.
- 1) Wypisz wszystkie osoby.
- 2) Wypisz wszystkie osoby , które są starsze niż 20 lat.
- 3) Wypisz wszystkie osoby , które są młodsze niż 18 lat o imieniu
- */
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.IO;
- using System.Collections;
- public class Cities {
- public string city { get; set; }
- public string country { get; set; }
- public long population { get; set; }
- Cities( string city, string country, long population) {
- this.city = city;
- this.country = country;
- this.population = population;
- }
- public Cities() {
- city = null;
- country = null;
- population = 0;
- }
- public void show() {
- Console.WriteLine(city + " " + country + " " + population );
- }
- }
- public class Person {
- public string firstName;
- public string lastName;
- public int age;
- public Person(string firstName, string lastName, int age) {
- this.firstName = firstName;
- this.lastName = lastName;
- this.age = age;
- }
- public Person() {
- firstName = null;
- lastName = null;
- age = 0;
- }
- public void showPerson() {
- Console.WriteLine(firstName + " " + lastName + " " + age);
- }
- }
- namespace zad1{
- class Program{
- static void Main(string[] args){
- string[] cities = {"lodz", "Leba", "Sopot", "Warszawa", "katowice" };
- var citiesQuery =
- from city in cities
- let len = city.Length
- where (len > 4)
- select city;
- var result = citiesQuery.Select(c => c.ToUpper());
- foreach (var item in result)
- Console.WriteLine("{0,1} ", item);
- //////////////////////////////////////
- Console.WriteLine();
- List<Cities> miasta= new List<Cities>();
- miasta.Add(new Cities() {city = "Warszawa" , country = "Polska", population = 1500000 });
- miasta.Add(new Cities() {city = "Moskwa" , country = "Rosja", population = 500 });
- miasta.Add(new Cities() {city = "Londyn", country = "Anglia", population = 7000000});
- miasta.Add(new Cities() {city = "Berlin " , country = "Niemcy", population = 40000});
- miasta.Add(new Cities() {city = "Wilno" , country = "Litwa", population = 1200000 });
- miasta.Add(new Cities() {city = "Minsk" , country = "Bialorus", population = 300});
- miasta.Add(new Cities() {city = "Kijow", country = "Ukraina", population = 2000000});
- miasta.Add(new Cities() {city = "Praga" , country = "Czechy", population = 1300000});
- miasta.Add(new Cities() {city = "Madryt", country = "Hiszpania", population =3200 });
- miasta.Add(new Cities() {city = "Paryz", country = "Francja", population = 5300000});
- IEnumerable<Cities> MiastoPowyzejStuTys =
- from miasto in miasta
- where miasto.population > 100000
- select miasto;
- foreach (var item in MiastoPowyzejStuTys)
- item.show();
- ////////////////////////////////
- Console.WriteLine();
- List<Person> osoby = new List<Person>(){
- new Person("daniel", "dembowski", 80),
- new Person("daniel", "wojciechowski", 60),
- new Person("adam", "sek", 7),
- new Person("michal", "fabisiak", 23),
- new Person("adrian", "michalik", 2),
- new Person("piotr","krwaczyk", 18),
- new Person("konrad", "rzepka", 12),
- new Person("kuba", "wojewodzki", 55),
- new Person("radoslaw", "majdan", 54),
- new Person("bronislaw","komorowski", 46)
- };
- IEnumerable<Person> ziomeczki =
- from osoba in osoby
- select osoba;
- foreach (var osoba in ziomeczki)
- osoba.showPerson();
- Console.WriteLine();
- IEnumerable<Person> ziomeczki2 = ziomeczki.Where(osoba => osoba.age > 20);
- foreach (var osoba in ziomeczki2)
- osoba.showPerson();
- Console.WriteLine();
- IEnumerable<Person> ziomeczki3 = ziomeczki.Where(osoba => osoba.age < 18 & osoba.firstName == "adam");
- foreach (var osoba in ziomeczki3)
- osoba.showPerson();
- Console.WriteLine();
- foreach (var osoba in ziomeczki)
- if(osoba.firstName == "michal")
- osoba.showPerson();
- Console.WriteLine();
- if (ziomeczki.Any(osoba => osoba.firstName == "michal")) {
- Console.WriteLine("Istnieje jakis michal na liscie");
- }
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement