Lexical
Identifiers
The characters a name may use, the camelCase house style, and the reserved name System.
since 0.1.0-alpha.1linuxwindowswasm
Description
An identifier names a variable, parameter, field, method, class, namespace or any other declaration. It starts with an ASCII letter or an underscore and continues with ASCII letters, digits and underscores:
[A-Za-z_][A-Za-z0-9_]*
Identifiers are case-sensitive, so total and Total are two different names. A name must not be a keyword (see lang.keywords). Non-ASCII letters, - and a leading digit are not allowed: café, my-var and 9x are compile errors.
Legal identifiers
int _count = 1;
int item2 = 20;
int total_so_far = _count + item2;
string userName = "ada";
console.writeln(total_so_far);
console.writeln(userName.startsWith("a"));
console.writeln("ada".toUpper());
21
true
ADA
Rules
- An identifier matches
[A-Za-z_][A-Za-z0-9_]*. The comparison is case-sensitive. - A keyword cannot be used as an identifier, with the member-name exceptions listed in
lang.keywords. - The names of the built-in types (
int,string,bool,float,char,voidand the sized numeric types) are ordinary identifiers, not keywords. - House style, which the standard library follows: names are camelCase. Each word after the first starts with a capital letter (
startsWith,toUpper,indexOf, notstartswith). Classes, interfaces, structs and enums start with a capital letter. The compiler does not enforce this. Systemis reserved for a built-in the language does not model. Do not use it as the name of your own declarations.
Examples
The same letters in different cases are different names:
Case matters
int total = 1;
int Total = 2;
console.writeln(total + Total);
3
Notes
The name System has no behaviour. The type checker treats an otherwise-unknown System as an untyped placeholder, so a bare System is accepted and does nothing useful; calling a method on it fails when the program runs. There is no System namespace or class in the standard library.