- Always use explicit types instead of
varwhen declaring variables - This improves code readability and makes the intended type clear to other developers
Do:
List<Artist> artists = new List<Artist>();
ArtistController controller = new ArtistController(mockRepo);
string name = "example";Don't:
var artists = new List<Artist>();
var controller = new ArtistController(mockRepo);
var name = "example";The only acceptable use of var is when the type is obvious from the right-hand side and using the explicit type would be redundant, such as:
var dictionary = new Dictionary<string, List<ComplexTypeName>>();But even in these cases, prefer explicit types for consistency.