Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

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
221,106 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.