csharp-notebooks
csharp-notebooks copied to clipboard
Modernized syntax, collection expressions and more explicitly typed variables
Pretty much what the title says:
//original
var names = new List<string> { "Sophia", "Rob", "Michelle" };
//updated
List<string> names = [ "Sophia", "Rob", "Michelle" ];
//original
for (var i = 0; i < words.Length; i++)
//updated
for (int i = 0; i < words.Length; i++)
From notebook 10 onwards, in the C# 101 section, suddenly everything is instantiated with var. In my opinion, if you're going to do that, at least dedicate a section to explain the possibility to do that because it just seems to come out of nowhere and feels like a different person wrote those sections compared to the previous ones. I changed a few to explicitly typed where I thought it would be important for a beginner to know what they're looking at but I have left most as they were since it's a judgment call or style preference what is "correct" there.