What should I call a variable instantiated with some type of array?
Is it okay to simply use a pluralised form of the type being held?
IList<Person> people = new List<Person>();
or should I append something like 'List' to the name?
IList<Person> personList = new List<Person>();
Also, is it generally acceptable to have loops like this?
foreach(string item in items)
{
//Do something
}
Rules for naming a variableA variable name can only have letters (both uppercase and lowercase letters), digits and underscore. The first letter of a variable should be either a letter or an underscore. There is no rule on how long a variable name (identifier) can be.
A variable name must start with a letter or an underscore character (_) A variable name cannot start with a digit. A variable name can only contain alpha-numeric characters and underscores ( a-z, A-Z , 0-9 , and _ ) Variable names are case-sensitive (age, Age and AGE are three different variables)
Variables of general types (primitive and composite data types) should be named logically. Variables of specialized types (extended data types) should have the same name as the type (which should have a logical name) but starting with a lower case character.
This is simple code convention, so you should go with what your team is used to. If you are single per project, just keep using the same convention whatever that is.
LE: the loop is ok, though it's a distinct question.
As mentioned before this is really very subjective but, I'd go for what looks best in the intellisense dropdown when you use the classes as that is probably the first point of interaction other developers using your code will have.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With