C# in Depth

Cover of C# in Depth
Order now (3rd edition)

Incorrect variable type claim

Chapter 8: Cutting fluff with a smart compiler: P212 and P213

Created: 6/10/2008
Last updated: 12/28/2008
Severity: Technical error

At the bottom of page 212, I use an example of:

var args = Environment.CommandLine;

and claim that args would be of type string[]. However, it would be of type string because that's the type of Environment.CommandLine. The same mistake is propagated on page 213, where I provide examples of using implicitly typed local variables for control structures, including this one:

foreach (var s in Environment.CommandLine)

I claim that s is of type string - but it would actually be of type char because string implements IEnumerable<char>.

The fix to both of these problems is simple - just replace the troublesome calls to Environment.CommandLine with Environment.GetCommandLineArgs() which really does return a string[]. The rest of the text is then accurate, and indeed it's the original meaning I intended.