20

When using variables of which their plural and singular are both the same, how do you name them? Are there any standards out there?

For example:

Series[] series  // Plural
Series series    // Singular

Indepth:

To be specific, my collection of series needs to be called series (due to JSON formatting), would you consider naming the singular form of Series that gets added to the collection Series s?

As in:

List<Series> series = new List<Series>();
Series s;

while (someBool)
{
    s = new Series();
    s.Name = "Name";
    while (anotherBool)
    {
        s.AddValue(someValue);
    }
    series.Add(s);
}

1 Answers1

18

I do not think there is a standard for this. The majority of english nouns does not come with this problem. So if you do not want to add a term like "list" or "collection" to the variable name, a possible solution is to circumvent that problem by simply choosing a different term.

In your example, one could use "sequence" instead of "series" (if that is the meaning of "series" you had in mind).

Of course, for some words like "spectacles" or "trousers" finding an appropriate synonym which fits to your context might not be easy. For those it is probably the best solution to follow @DavidPacker's suggestion to use a word like "spectaclesCollection" or "trousersList".

Doc Brown
  • 218,378