Iterative naming variable in .NET.

In the standard foreach loop, is there a common naming convention for an iterator variable?

Typically, I use currXXX, where XXX is essentially the name of what I'm looking at. I have not seen others follow this agreement, this is just what I did, as far as I remember. I see that the meaning has a name similar to what I repeat.

Any opinions? Any "official" recommendations?

foreach(var currName in names)
{
   //do stuff
}
+3
source share
5 answers

There are no official recommendations that I know of, but I tend to use the template foreach (var singular in plural). For example:

foreach (var name in names)
{
    // do stuff
}
+13
source

Use the plural and singulare as others say, and avoid "curr".

, "current". , curr, s ( ), ( ) , . - ( ). , , dpdl dropdownlist ..

+2

, , :

foreach (var single in plural)

(, ). :

foreach (var item in plural)
+1
, . :
foreach(string name in names) {}
foreach(Car car in cars) {}
foreach(User user in users) {}

!

0

I would not var in this case, because he did not understand what type of currName.

I would explicitly indicate the type:

foreach(YourType currName in names)
{
   //do stuff
}
0
source

Source: https://habr.com/ru/post/1717650/


All Articles