DevCity.NET -
Book Review: Murach's C# 2005
Scott Waletzko

Scott Waletzko has been an Information Technology professional and Windows / Web programmer since 1995, with experience in software development and architecture, network design and administration, and project and team management. Currently he is the the Senior Vice President of Technology at Intellisponse, as well as the President of Skystone Software / Echosoft Design Studios, LLC.

At Intellisponse, Scott is responsible for architecture and implementation of the company flagship software called Synapse, the first full-featured Web survey authoring tool for market research, enabling researchers to design, publish, and manage full-featured and logically complex questionnaires to the Internet without programmer interaction.

As president of Skystone Software / Echosoft Design Studios, LLC, Scott is developing a unique Web site content management system named Tempest, which will drive and provide comprehensive Web site hosting and content management to anyone with a Web browser.

by Scott Waletzko
Published on 6/15/2006
A review of Murach's C# 2005 tutorial and reference book, written by Scott Waletzko (Skystone Software).


C# 2005, written by Joel Murach, is a comprehensive tutorial that walks C# beginners through the basics of C# syntax, Windows Forms programming, and ADO.NET database development using Visual Studio 2005. The first half of the book covers working with Visual Studio to create a new Windows Forms project and write basic C# code, including an introduction to variables, control structures, exceptions, arrays and collections. The second half of the book introduces more advanced programming concepts such as object-oriented development including class creation, delegates and events, inheritance, interfaces, and generics, and database programming with ADO.NET including brief tutorials on data binding and data-bound controls. The book closes with a few chapters describing application deployment, Xml development, and files and data stream access methods.

In classic Murach style, every two pages in the book repeats the contents twice; the left-hand page is a detailed description of the concept being covered written in a conversational tone, and the right-hand page contains a recap of this discussion in bulleted-form, with screenshots and / or code samples. This layout is ideal for both novice and expert readers alike; beginners learn faster when a concept is restated / repeated, and experts can skim through the right-hand pages looking for content that is new to them.

There are no assumptions going into the book about the reader's knowledge of programming or C#.   As such, both beginners and experienced developers will have something to gain from reading it (but anyone who has used C# before can likely just skim through the first half). The book is meant to be an introduction to the concepts it covers and does a great job at that task, going shoulder-deep into some concepts and waist-deep into others.   


Walkthrough: Section 1

The first section in the book ("An Introduction to Visual Studio") is designed to get programmers new to Visual Studio up and running in the IDE (Integrated Development environment). In these pages, the reader is introduced to the basics of Visual Studio development ("Windows Forms and Web Forms applications", "Visual Studio and the .NET programming language", "The Visual Studio IDE"), to the C# programming language ("How a C# application is compiled and run", "How C# differs from Java"), and to the .NET framework ("The .NET framework", "How C# differs from the other .NET languages").

 The second half of this section covers the Visual Studio IDE (giving examples from the Professional edition, but including notations describing the differences of the Express edition), walking through the basics of starting Visual Studio, opening and closing projects, using the Form designer, the Code editor, the Solution Explorer, and other various windows and menu options ("Some possible menu variations", "How to work with Visual Studio's windows") .

Closing out the chapter is a brief discussion covering compiling and running a test project ("How to build a project", "How to run a project"). By the time the first chapter is completed, the reader should feel comfortable manipulating the Visual Studio IDE.

"Chapter 2 - How to design a Windows Forms application" is about project management and basic form design, beginning with an introduction to Visual Studio customization ("How to set the options for project and solutions", "How to change the import and export settings"), introducing the first form in the sample application used throughout the book ("The design of the Invoice Total form"), and walking the reader through adding controls to an empty form ("How to add controls to a form", "How to set properties", "Common properties for forms and controls").

Rounding out the first section in the book is a chapter completing the introduction to application development, entitled "How to code and test a Windows Forms application". Backing up slightly, this chapter begins by introducing object-oriented programming concepts ("How to refer to properties, methods, and events", "How an application responds to events") and then goes on to explain how to hook event handlers up to the form and controls created in the second chapter ("How to create an event handler for the default event of a form or control", "How to delete an event handler", "The event handlers for the Invoice Total form"). From there, the author takes the reader on a brief wallthrough of proper code structure ("How to code in a readable style", "How to code comments", "How to collapse or expand blocks od code"), and then into a discussion of some new time-saving additions to Visual Studio 2005 ("How to use code snippets", "How to refactor code").


Walkthrough: Section 2

Anyone with any experience using Visual Studio for Windows Forms development may want to skip the first section and start right in with "Section 2 - The C# Language Essentials". These 8 chapters serve as an introduction to the building blocks of the C# programming language, covering how to work with different variable types, code control structures, exceptions, methods, and events. When looking at this section's topics in the table of contents it doesn't appear that they appear in any particular order, but when reading the chapters sequentially everything seems to flow nicely.

"Chapter 4 - How to work with numeric and string data" begins by explaining the basics of working with value type variables, and covers declaration and initialization, arithmetic and assignment expressions, order of precedence, and casting. This chapter provides a very solid foundation for working with value types, specifically using strings and numeric variables to illustrate how and why to cast values to specific types, how to create formatted string representations of different types (using the String.Format method), and includes a brief mention of the Math class and its associated methods (the StringBuilder and the differences between mutable and immutable string values are covered in a later chapter).

The next chapter ("How to code control structures") introduces relational and logical operators, conditional statements ("How to code if-else statements", "How to code switch statements"), and loop constructs ("How to code while and do-while loops", "How to code for loops").

Chapter 6 is a discussion on "How to code methods and event handlers", expanding on what is covered in the first section of the book by detailing the differences betwen value and reference parameters, using Visual Studio 2005's refactoring feature to convert a block of code into its own method, and explaining in detail how events and event handlers work ("How to work with events and delegates", "How to generate an event handler for an event", "How event wiring works", "How to handle multiple events with one event handler").

The next chapter ("How to handle exceptions and validate data") begins by covering exception handling, explaining the specifics of the proper handling of exceptions through structured try-catch blocks, and introducing the proper reasons and methods for throwing exceptions in your code.

Following is a chapter on arrays and collections, covering the use of single- and multiple-dimensional arrays ("How to work with one-dimensional arrays", "How to work with rectangular arrays", "How to work with jagged arrays") and collections ("Commonly-used collection classes", "Typed vs. untyped collections"). The array discussion ends with more advanced examples of how to manipulate arrays ("How to refer to and copy arrays", "How to code methods that work with arrays"), and the collection discussion details the different built-in collections (including list, sorted list, queues, and stacks) and how and when to use each.

"Chapter 9 - How to work with dates and strings" extends the previous discussion of formatting strings, introduces the DateTime and TimeSpan structures, and explains how to manipulate, compare, and format date-related values.

Moving back to the sample application, the next chapter begins with examples of working with some of the more common controls (comboboxes, listboxes, checkboxes, radio buttons, and groupboxes), explaining tab order, and then illustrating how to use the Visual Studio reference documentation to learn more about the controls not covered in the book. The next discussion is about using multiple forms in one application ("How to work with a multi-form project", "How to use the MessageBox class", "How to display a dialog box and get the user response", "How to use the FormClosing event"), ending with example code integrating everything discussed in the previous chapters into the sample project that is used throughout the book.

The last chapter in this section, "How to debug an application", covers the debugging features of Visual Studio including break mode, edit and continue, breakpoints, the various debug windows (Watch, Locals, Autos, and Call Stack), and the use of Visual Studio 2005's new visualizers to view variable content. Not mentioned are the System.Diagnostics.Debug class, the different build configurations, or conditional compilation constants; all of which might have fit nicely in this chapter.


Walkthrough: Section 3

The third section of "C# 2005" covers object-oriented programming, including class and structure design, indexers, delegates, events, inheritance, interfaces, and generics. Beginning programmers may be well served to take a break between sections 2 and 3 and become more familiar with everything they have learned up until that point, because these are advanced concepts relative to what is covered in the previous chapters.

The section starts off with a comprehensive chapter covering class design, beginning with an introduction to the concepts of using classes ("How classes can be used to structure an application", "The members you can define for a class", "How instantiation works"), moving into the details of class design (covering fields, properties, methods, constructors, and static methods), and closing with a discussion of how to create and use structures.  

Chapter 13 covers a few miscellaneous class design concepts, including the use of indexers, delegates, events, and operators. Operator overloading is explained, at which time the author also explains the use of the virtual Equals and GetHashCode methods of the base Object class.

The next topic covered is inheritance. The chapter begins with an overview of class inheritance, a correlation to how inheritance is used in the .NET framework classes, and an explanation of how inheritance can be used by the reader to develop robust applications. Specifics are then covered ("How to create a base class", "How to create a subclass", "How polymorphism works"), and related code examples are given via the book's sample application. Before moving on, the Type class, casting inherited classes, and the concepts of sealed and abstract classes are discussed. Inheritance can be a tricky concept to pick up, and the author does a great job of explaining the process conceptually and then by example in this chapter.

Chapter 15 introduces interfaces and generics. The first part ("How to work with interfaces") walks the reader through interface implementation concepts and practices in much the same fashion as the previous chapter did with inheritance, illustrating some of the common interfaces defined within the .NET framework and how and why to implement them. Also covered is referring to instantiated classes by their interface and passing interfaces as parameters, key points towards understanding why use of interfaces is important towards proper object-oriented development.

The pages about generics introduce this concept (new to Visual Studio 2005), illustrate how to code classes that use generics ("How to code a class that defines a generic collection"), introduce some generic interfaces in the .NET framework library and how (and why) to use them ("How to implement the IComparable<> interface", "How to implement the IEnuerable<> interface"), and  illustrate how to write interfaces that use generic members ("How to code an interface that uses generics", "How to use contraints").

"Chapter 16 - How to organize and document your classes" rounds out the section by introducing the Visual Studio Xml documentation methods, examining class libraries ("How class libraries work", "How to create a class linrary project", "How to add a reference to a class library"), and discussing the different ways to define classes (more than one class per file, partial classes across multiple files) in Visual Studio 2005.



Walkthrough: Section 4

Section 4 serves as an introduction to database programming, beginning with a tutorial on relational database design ("An introduction to database programming") that nicely covers basic and even intermediate relational database concepts and practices such as table design, indexing, queries, and joins. Rounding out this chapter is an overview of ADO.NET, which illustrates the concepts behind .NET's data connectivity library (".NET data proividers", "How the basic ADO.NET components work", "Concurrency and the disconnected data architecture")and introduces the key players ("How a dataset is organized", "How to work with data without using a data adapter").

The first half of the rest of this section covers using data binding to bind controls to data sources. Chapter 18 walks the reader through the process of creating a data source using the Data Source Confguration Wizard, and how to bind it to a DatagridView control (the new DataGrid introduced in Visual Studio 2005), a TextBox control, and a ComboBox control. Throughout this chapter, the author throws in additional information such as data source-specific error handling ("How to handle data provider errors", "How to handle ADO.NET errors") and nicely anticpates issues such as formatting ("How to format bound data") and query building ("How to create a parameterized query", "How to preview the data for a query", "How to view the schema for a dataset").

Chapter 19 continues the data source discussion by introducing the DataSet Designer and Query Builder as vehicles for automating data connectivity in Visual Studio applications ("How to use the DataSet Designer"), a discussion of typed datasets ("How to use code to work with a binding source or dataset"), and more advanced use of the DataGridView, specifically how to create a Master / Detail form. All of the concepts in the last two chapters are summarized using code samples from the sample application.

After covering data binding and the automated data access methods available to C# programmers, the author moves on to describe the programmatic methods of data access in "Chapter 20 - How to use ADO.NET to write your own data access code". If the previous ADO.NET data access methods are akin to teaching someone how to drive a car, this chapter is like opening the hood and handing them a wrench. Topics covered are "How to work with connections and commands", "How to execute data commands", "How to work with datasets and dataadapters", and "How to work with transactions".

The last chapter in the data access section takes the reader into advanced territory by explaining data-bound application architecture, examining the different layers of a networked and database-driven system and showing (by example) how classes can be made data-aware and bound to controls just like ADO.NET data sources. Just the inclusion of these topics in a book that is otherwise geared to those just starting out with C# programming shows that Murach is dedicated to showing his readers the paths to advanced topics, giving them the option to explore them further when they are ready.



Walkthrough: Section 5

The last section in the book, "Other Skills for C# Developers", is a collection of assorted techniques, namespace overviews, and design practices, all of which are prerequisites to creating a production-ready application. Topics covered range from file I/O to Xml to UI design practices and deployment.

First up in this section is a chapter on using the System.IO namespace to access folders and files on disk. Just an overview (the details of working with streams are mostly glossed over), this chapter is an introduction to reading and writing text and binary files using the TextReader / TextWriter and BinaryReader / BinaryWriter classes.

"Chapter 23 - How to work with Xml files" beings with an introduction to Xml document syntax, breaking down tags, declarations, comments, elements, and attributes, and showing the reader how to edit Xml files in Visual Studio using the Xml Editor. The chapter closes with a discussion of using the XmlReader and XmlWriter classes to read and write Xml. Again, the chapter just starts the reader down the path, making no mention of the XmlDocument class or any other advanced topics such as DTD or XSLT (which are complex enough to merit a book of their own).

The next chapter outlines user interface design best practices, discussing SDI (Single-document Interface) and MDI (Multiple-document Interface) application designs, tab controls, menus, toolbars, and help integration basics. Like the other chapters in this section, these topics are only briefly touched upon, but there is enough information provided to ensure that beginner programmers will be able to build a standardized user interface without difficulty.

Completing the book is a chapter on application deployment, which examines the different methods of deploying a compiled program. After introducing the concepts behind XCopy, ClickOnce, and a Setup program, the options for using each are described. The chapter is rounded out with a discussion about database application deployment options, covering each model (networked database application, client database application, and Web server database applications).



C# 2005 by Joel Murach is a comprehensive tutorial that properly introduces beginner developers or programmers new to C# to the gamut of language and IDE features available to them in Visual Studio 2005. I would also recommend this book as a reference or tutorial to experienced developers who are interested in rounding out their object-oriented programming or data access techniques, or who are interested in learning more about the features introduced to .NET and C# in Visual Studio 2005.

The tone of the book and its organization and paired page layout are very conducive to learning at any level, and the topics covered are varied enough to ensure a well-rounded learning experience, regardless of the reader's development background.