Sooo... I'm not sure how everyone else figured this out unless they went straight to the code download:
Somewhere around Chapter 4 the author starts using
instead of
Code:
Console.WriteLine()
.
I thought I knew the answer - just add
Code:
using System.Console;
to the top of my C# code file.
Well, that doesn't work.
So I downloaded the sample code for this book and opened it, and discovered that all of the source files have this near the top:
Code:
using static System.Console;
Still not sure where this came from, I went back and re-read chapter 3.
There, at the VERY END of chapter 3, in the very last paragraph hides a very IMPORTANT clue:
"when the using static System.Console namespace is added to the list of included namespaces, accessing the WriteLine() method no longer requires the preceding static class name"
If you're not carefully reading every word of this book, you'll miss this information. In my opinion the authors should have emphasized this.
To make it more confusing, the exercises in the book are not "complete". In other words, the instructions say to create a new console application (for example) and then they give you the code that goes inside static void Main.
What's not obvious in any exercise is that the Main method is just a portion of the complete code. ("Main" is inside of "class Program", which in turn is inside of "namespace".)
Yes, Visual Studio adds all of that for you. Fair enough. But what it does NOT automatically add is "using static System.Console;" and THAT is the important missing piece.
If you don't add this line at the top of your code, "WriteLine()" will not work.
By the way:
I understand and appreciate how the authors chose to print partial code blocks in the book. My point is, at least somewhere in the book, they should have made it REALLY clear to everyone how/why "Console.WriteLine()" can be replaced with "WriteLine()"
Other than that, I am really enjoying the book.