repl.it
@kironroy/

querywithlinq

C#

No description

fork
loading
Files
  • main.cs
  • Bird.cs
  • BirdRepository.cs
  • main.exe
  • Place.cs
  • Random.cs
  • Sightings.cs
main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BirdWatcher
{
    class Program
    {
        static void Main(string[] args)
        {
            var birds = BirdRepository.LoadBirds();

            var totalBirdCount = birds.Count();
            Console.WriteLine($"Total bird count: {totalBirdCount}");

            Console.WriteLine(); // breakline

            var totalBirdSightings = birds.SelectMany(b => b.Sightings).Count();
            Console.WriteLine($"Total bird sightings: {totalBirdSightings}");

            Console.WriteLine(); // breakline

            var averageBirdCount = birds.Select(b => b.Sightings.Count()).Average();
            Console.WriteLine($"Average bird count: {averageBirdCount}");

            Console.WriteLine(); // breakline

            var birdSightingsByCountry = birds.SelectMany(b => b.Sightings).Select(s => s.Place.Country);
            Console.WriteLine(birdSightingsByCountry.ToString());

            Console.WriteLine(); // breakline

            var statuses = birds.Select(b => b.ConservationStatus).Distinct();
            Console.WriteLine(statuses);







            Console.ReadKey(); // clean line
        }
    }
}