Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6863033
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T02:44:00+00:00 2026-05-27T02:44:00+00:00

Firstly, thanks a ton to the StackOverflow community. I am new to C#, and

  • 0

Firstly, thanks a ton to the StackOverflow community. I am new to C#, and this group has pulled me out of the fire many times!

Issue: I am having a bit of trouble with the C# FindAll method. Specifically, I can’t make it work, and I know it is me…

Stuff that works fine:

public class City
{
   public string Name {get;set;}
   public string Country {get;set;}
}

public List<City> GetCities()
{
   List<City> cities = new List<City>();
   cities.Add(new City() { Name = "Istanbul", Country = "Turkey" });
   // etc, add a bunch more cities, including multiple entries for 
   // some cities
   return cities;
}

Now what doesn’t work… (It returns all the cities or none (depending on how I fiddle the syntax).

public static List<> ReturnCityList(string CityName)
{
  Cities = GetCities;
  var RequestedCities = Cities.Findall(s => Name.Equals(CityName));
  return RequestedCities
}

What am I doing wrong?

I have read a lot of examples, but am missing something.

Thank you!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T02:44:00+00:00Added an answer on May 27, 2026 at 2:44 am
    var RequestedCities = Cities.Findall(s => Name.Equals(CityName));
    

    Where is Name coming from? Did you mean this?

    var RequestedCities = Cities.Findall(s => s.Name.Equals(CityName));
    

    Or even

    var RequestedCities = Cities.Findall(s => s.Name == CityName);
    

    Which does the same thing with a simpler syntax.

    You aren’t using the s variable, i.e., the variable that holds the current element in the iteration. That’s what you likely need to check against CityName. I doubt your version even compiles. Also…

    public static List<> ReturnCityList(string CityName)
    

    That won’t compile. You can’t use an empty generic argument, you need to specify the return value as List<City> and then you will need to call ToList() on the result of the query. There are a couple other errors as well.

    Honestly you should probably just return an IEnumurable<City> as the caller probably doesn’t need to modify the return value, just enumerate it.

    One more nitpick; method arguments use camelCase by convention, not PascalCase, as do local variables.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly, YES, this is a duplicate issue that's been asked 100 times on here,
Firstly Id like to say thanks to everyone who has helped me this week
Firstly just a big Thanks to everyone on this site, I am using it
Firstly thanks in advance for your time looking at this question. I'm trying to
Hey, firstly thanks for reading this. I am a bit of a noobie c++
Firstly, thanks for taking the time to read this and possibly comment on it.
Firstly, I'm new to Python, Qt and PySide so forgive me if this question
Firstly, I wrote my customized setter for an NSString* like this: - (void)setDateString:(NSString *)newDateString
Firstly some background,.. IVe started a new job as PHP developer with a company
Firstly sorry if this is a common question but I couldn't find anything on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.