Use predefined type names and implicit typing
mainType Declarations
- Predefined Aliases: Use
int,float,string, andboolfor local, parameter, and member declarations. - .NET Framework Names: Use
Int32,Single,String, etc., only when accessing static members (e.g.,Int32.Parse).
Implicit Typing
- Use
var: Usevarfor local variable declarations to reduce clutter, especially with complex generic types. - Exception: Do not use
varfor primitive types; use the predefined names (e.g.,int index = 100;).
// Correct
string firstName;
int lastIndex;
string commaSeparatedNames = String.Join(", ", names);
// Use var for complex types
var stream = File.Create(path);
var customers = new Dictionary<string, string>();
// Exception: Use explicit types for primitives
int index = 100;
string timeSheet;