FAQ: LINQ - LINQ with Other Collections

This community-built FAQ covers the “LINQ with Other Collections” exercise from the lesson “LINQ”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Build Web Apps with ASP.NET

FAQs on the exercise LINQ with Other Collections

There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply (reply) below.

If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.

Join the Discussion. Help a fellow learner on their journey.

Ask or answer a question about this exercise by clicking reply (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

Hey, for some reason this code didn’t pass, even though it did what was required:
var dotSeven = from x in heroesList
where x.Contains(".")||x.Contains(“7”)
select x;

Hey,
I also had frustrations discovering that Codecademy wants us to write this one in a single Method syntax (even though the provided example uses Query syntax, which is kind of confusing).

Here is the correct solution, the lines that are commented out are an alternative using Query syntax:

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

namespace LearnLinq
{
  class Program
  {
    static void Main()
    {
      List<string> heroesList = new List<string> { "D. Va", "Lucio", "Mercy", "Soldier 76", "Pharah", "Reinhardt" };

      /*var periodOrSeven = from h in heroesList
        where h.Contains(".") || h.Contains("7")
        select h;*/

      var periodOrSeven = heroesList
        .Where(x => x.Contains(".") || x.Contains("7"));

      foreach (string x in periodOrSeven)
      {
        Console.WriteLine(x);
      }

    }
  }
}
3 Likes

Yeah, first I used query syntax which was not necessary. I think Codecademy recommends that I use method syntax when the thing that I am selecting doesn’t get changed by select which or there is no need for where.

1 Like