string[] Names = {};
string[] names = {};
Is it better to use a capital letter? Is convention the same for arrays and other types?
string[] Names = {};
string[] names = {};
Is it better to use a capital letter? Is convention the same for arrays and other types?
You'll notice in C# examples and .NET framework naming, that in general, everything is camelCase
:
lowercaseCamelCase
name.class
, struct
, enum
, delegate
), methods, and properties should have an UppercaseCamelCase
(aka PascalCase
) name.Here is an example:
// Types are CamelCase
class Foo {
// Properies are PascalCase
public int SomeProperty { get; set; }
// *Private* fields are lowerCamelCase
private int aField;
// By some conventions (I use these)
private int m_anotherField; // "m_" for "member"
private static object s_staticLock; // "s_" for "static"
// *Public* fields are PascalCase
public int DontUsePublicFields; // In general, don't use these
public const int ConstantNumber = 42;
// Methods are UpperCase
// Parameters and variables are lowerCase
public SomeMethod(int myParameter) {
int[] localVariable;
//string names[] = {}; // Not valid C#!
string[] names = new string[] { "Jack", "Jill" };
}
}
See also:
Are all of those valid? Is it better to use a capital letter?
The last (string names[] = {};
) is not valid C#. The other two are correct in terms of syntax.
The suggested capitalization for a variable depends on the usage. Local variables or parameters to a method typically would be named with a lower case letter (technically, camelCase), fields properties would be upper case (technically, PascalCase). For details, see the Capitalization Conventions.
Note that these conventions have nothing to do with the type of variable, but rather it's usage. The fact that you're dealing with an array shouldn't necessarily change the variable's name - at least not the capitalization of the variable name. (You may, however, want to use a name that suggests that the variable is a "collection" of some form.)
That being said, this is purely a convention, and it is entirely up to you what naming you use.
If it is better to use a capital letter, does this mean that the arrays are treated as objects?
Capitalization has nothing to do with how variables are treated - only their types. Changing the capitalization may suggest to other developers that the type is a field or property, but it does not actually change the variable in any way from the language or usage perspective.