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

  • Home
  • SEARCH
  • 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 349723
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T11:29:06+00:00 2026-05-12T11:29:06+00:00

I have always thought it was best practice to be explicit in naming my

  • 0

I have always thought it was “best practice” to be explicit in naming my collection variables. So, if I had a collection of Car objects, I would typically name a Car[] carArray and a List<Car> carList.

And then 99% of the time, I end up just doing something like…

foreach (Car car in carArray)
{
    ...
}

…and I’m thinking, I could have just called the array cars, and it wouldn’t have made any difference.

And now that we have IEnumberable<T>, I’m actually faced with the question of whether I might consider writing something like carIEnumerable? or carEnumerable. So far, the answer has been “no”.

My thinking here is that the type of collection often doesn’t matter, and when it does, is still doesn’t matter if the collection type is written into the variable name. I just had a case where I had to switch from an IEnumerable<Car> to a List<Car> because I needed “bracket access” to the items (e.g., carList[3]). In that case, the two collection types do not behave the same, but would naming the variable cars have been a problem here?

Not to add another layer of complexity to this question, what happens if I use var? E.g.,

var cars = GetCars();

I can certainly tell cars is some kind of collection. I can iterate it. If I’m using LINQ, I can use extension methods. More importantly, if I later change up the type of collection, there would be much less code to mess with. var would still be var and cars would still be cars. That seems very appealing to me, and I having trouble seeing much disadvantage.

So, just to make sure my question is clear: How do you name your collection variables and why? Is there a serious readability or clarity cost to just “pluralizing” the name of the item?

  • 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-12T11:29:06+00:00Added an answer on May 12, 2026 at 11:29 am

    The problem with this kind of naming is that it concentrates too much on the actual implementation rather than the purpose of the property. Instead of CarArray, you could use OwnedCars, or whatever tells the user why that enumeration is there.

    I think naming the loop variable “car” in a small foreach-loop is just fine.

    If you write var cars = GetCars(), the compiler looks at the type on the right side of the assignment, in this case possibly IEnumerable<Car>, and gives cars that type. You can even see it in subsequent uses of the variable if you hover over it with your mouse.

    If you change the type of a collection and don’t have to change your code because you are using var, think about the fact that those different types of collections probably have something in common that enables you to perform the same operations on them.
    Probably it’s IEnumerable if you use them in foreach loops.

    So you could just as well expose those collections as IEnumerable, so users of your class don’t depend too much on a certain implementation.

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

Sidebar

Related Questions

I have always thought that the .equals() method in java should be overridden to
I have always thought that the terms internationalization and localization (and their funny abbreviations
We have always had languages that were preferable to be used in a particular
i have always thought that returning Arrays were better than lists when having a
gcc 4.4.4 c89 I have always thought of using malloc for the life of
I have always used || (two pipes) in OR expressions, both in C# and
I have always wondered how people update a previous line in a command line.
I have always made a point of writing nice code comments for classes and
I have always been for documenting code, but when it comes to AJAX +
I have always wondered WHaT tHE HecK?!? is the difference between JScript and JavaScript.

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.