C# Querying With LINQ Now You're Querying Selecting, Projecting and Anonymous Types

How to do this in repl.it please? Or maybe Visual Studio?

I'm not going to use csharp console for this course. I've been using repl.it to follow along and I need help understanding how to make the query work in repl.it

My code :

Birds.cs

//Objec initialization

 public class Bird
 {
   public string Name{get; set;}
   public string Color{get; set;}
   public int Sightings{get; set;}




 }

Main.cs

using System;
using System.Linq;
using System.Collections.Generic;





class MainClass {
  public static void Main (string[] args) {

    List<Bird> birds = new List<Bird>
        {
          new Bird
          {
            Name = "Cardinal",
            Color = "Red",
            Sightings = 3
          },
          new Bird
          {
            Name = "Dove",
            Color = "White",
            Sightings = 2
          }

        };
    var canary = new Bird 
    {
      Name = "Canary", 
      Color = "yellow",
      Sightings = 0
    };

    birds.Add(canary);

    foreach(Bird bird in birds){
      Console.WriteLine(bird.Name + " " + bird.Color + " " + bird.Sightings);
    }

     query = from b in birds where b.Color == "Red" select b;

      Console.WriteLine(query);


  }
}

I'm having an issue with trying to display the LINQ query after the C# foreach loop data

 query = from b in birds where b.Color == "Red" select b;

      Console.WriteLine(query);

repl.it link : https://repl.it/@agent1red/LINQTraining

Someone else's repl example of LINQ but not a list: https://repl.it/@Ecliptor/C-Linq-Example

I just can't follow along with the console. Does anyone know if I can use Visual Studio? Which project should I select? Do I need to install a LINQ package in VS?

1 Answer

Steven Parker
Steven Parker
174,022 Points

Two things to keep in mind about using the workspaces:

  1. It's easier to follow along using the same tools as the instructor. You need to be very familiar with any external tool to know when (and how) to alter the steps the instructor is using.
  2. With a workspace, it's easy to create a "snapshot" and share a link to it so other students can replicate and analyze your issue if you need help.

But with that said, you can use an external build environment. And if you were missing the LINQ package, you should get a compiler error from the "using System.Linq;" directive.