Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 6 > BOOK: Beginning C# 6.0 Programming with Visual Studio 2015
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning C# 6.0 Programming with Visual Studio 2015
This is the forum to discuss the Wrox book Beginning C# 6.0 Programming with Visual Studio 2015 by Benjamin Perkins, Jacob Vibe Hammer, Jon D. Reid; ISBN: 978-1-119-09668-9
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning C# 6.0 Programming with Visual Studio 2015 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old June 21st, 2016, 09:06 PM
Registered User
Points: 5, Level: 1
Points: 5, Level: 1 Points: 5, Level: 1 Points: 5, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2016
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow Console.WriteLine mysteriously becomes WriteLine

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
Code:
WriteLine()
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.
Reply With Quote
  #2 (permalink)  
Old August 16th, 2016, 01:16 PM
Registered User
Points: 13, Level: 1
Points: 13, Level: 1 Points: 13, Level: 1 Points: 13, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2016
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

At the very top of page 51, at the very end of chapter 3, it says:
"All code examples requiring the System.Console static class from this point forward include the using static System.Console keyword."

I agree that it was very easy to miss that. It would have been better if it had been called out as a NOTE
Reply With Quote
  #3 (permalink)  
Old July 4th, 2017, 01:03 PM
Registered User
Points: 8, Level: 1
Points: 8, Level: 1 Points: 8, Level: 1 Points: 8, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2017
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Same Issue with System.Convert

I experienced the same problem with .Convert as is mentioned for .Console.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Ex 19-4 Console.WriteLine question zavodney BOOK: Stephens' Visual Basic Programming 24-Hour Trainer 2 August 14th, 2011 11:39 PM
Ch3 Ex2 Console.WriteLine question thelafe BOOK: Beginning Visual C# 2010 2 June 11th, 2011 09:40 AM
writeline to an application Vinny_68 Pro Visual Basic 2005 0 April 16th, 2007 10:40 AM
Problem with First.cs output via Console.WriteLine patrick764 C# 1 November 7th, 2005 03:17 PM
Console.WriteLine ritag ADO.NET 2 February 9th, 2005 11:09 AM



All times are GMT -4. The time now is 03:42 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.