Customer Service 1-800-221-5528

Murach’s C# (8th Edition)

by Anne Boehm and Joel Murach
22 chapters, 772 pages, 332 illustrations
Published April 2022
ISBN 978-1-943873-07-4
List price: $59.50

Ever since the 1st Edition of this book was published in 2004, it has been a favorite of instructors and students alike because of the clear, concise way it teaches C# and object-oriented programming. Now, this 8th Edition has been updated and streamlined to do a better job than ever of showing how to develop professional Windows Forms applications with C#.

Although this book is designed for introductory C# courses, it also works for object-oriented and database programming courses.

Now available as a Canvas course!

The Canvas course file contains all the objectives, quizzes, assignments, and slides that you need to run an effective course. It only takes a few clicks to import it into the Canvas LMS. Then, you can customize it for your course. Learn more.

Best C# book ever. Murach manuals are precise and to the point, with lots and lots of examples. Highly recommended for beginners."

Posted at an online bookseller

  • About this Book
  • Table of Contents
  • Courseware
  • FAQs
  • Corrections

Book description

Section 1: Introduction to program development

The 3 chapters of section 1 show your students how to use the Visual Studio IDE to develop Windows Forms applications…an approach that suits today’s visual learners by letting them see what they’re making. In particular, these chapters focus on the skills for designing forms and entering code. These are essential skills your students need to get the most out of Visual Studio.

Section 2: Language essentials

The 8 chapters of section 2 present a professional subset of C# that includes all of the essential programming skills for developing business applications. That includes the best techniques for handling exceptions, validating data, coding control structures, working with arrays and collections, handling various types of data, and debugging applications.

Section 3: Object-oriented programming

The 5 chapters of section 3 present a professional set of skills for creating and using classes. To start, chapter 12 presents the basic skills every student should know. Because the other chapters present advanced skills, you may want to be selective about which of these chapters or portions of chapters you assign.

Section 4: Basic skills for working with data

The 2 chapters of section 4 present skills for working with data outside of a database. To be specific, they show how to work with text and binary files, as well as how to use LINQ to query a data structure.

You can decide whether you want to cover the chapter on file I/O or whether to point to it as a reference if students ever need to work with files. But you’ll want to be sure to cover the chapter on LINQ before going on to EF Core in section 5.

Section 5: Database programming

The 4 chapters of section 5 present the essential skills for developing applications that work with databases. That includes using Entity Framework (EF) Core to work with the data in a relational database and using ADO.NET to provide the data access code. It also includes using the DataGridView control of the .NET Framework to display and manipulate database records in an application.

What courses this book can be used for

This book is designed for introductory C# courses. But it also works for object-oriented and database programming courses, so you may want to consider it for a two- or three-course sequence.

Introductory courses

For an introductory course, this book gives your students a realistic view of how Visual Studio and C# are used to develop Windows Forms applications. By the time your students complete chapter 7, for example, they will be able to develop tested, reliable applications that do data validation and exception handling. And by the time they complete chapter 12, they’ll be able to develop object-oriented applications.

Advanced courses

This book is also ideal for advanced courses:

  • In sections 1 and 2, your students can review the essential skills that they should have already learned from an introductory course but often don’t.
  • In section 3, your students can learn all of the intricacies of object-oriented programming.
  • In section 4, your students can learn how to work with text and binary files and how to use LINQ to query various data structures, in preparation for using LINQ with EF Core.
  • In section 5, your students can learn how to develop database applications using EF Core, ADO.NET code, and the DataGridView control.

Presentation options

After your students complete the first 12 chapters, you can go on to any other section of the book. This works because these sections are written as independent modules that require only the first 12 chapters as a prerequisite.

In addition, most of the chapters in sections 4 and 5 are independent of each other, so they can be taught in any order. That’s what we mean by modularity, and that lets you create the course that’s right for your students.

The main points here are that (1) you don’t need to teach the chapters in sequence and (2) you get to decide the focus of your course.

If, for example, you want to emphasize the complexities of object-oriented programming, assign all of section 3. If you want to emphasize database programming, assign chapter 18 and all of section 5. If you want to teach a course that introduces all aspects of programming, assign selected chapters from sections 3, 4, and 5.

 

"There's too much content for my course"

That’s a complaint we sometimes hear, and we realize it may be an issue with a book that’s almost 800 pages!

Remember, though, that the modular structure of this book lets you assign just the content that you want for your course, whether it’s a beginning or advanced course.

Book features

Like all our books, this one has features that you won’t find in competing books. That’s why we believe that your students will learn faster and better with our book than with any other. Here are just 3 of those features.

  • Unlike some C# books, this book shows your students how to get the most from Visual Studio.
  • Unlike most C# books that are used for introductory courses, our book shows how to develop real-world applications.
  • Like all our books, this C# book presents all the material in what we call paired pages, where every 2-page spread explains and illustrates a single topic. That means less reading, easier reference when working on labs, and quicker review when prepping for exams.

What’s new in this edition

In you’ve been using the 7th Edition, you’ll find it’s pretty easy to revise your course for this 8th Edition. That’s because not much has changed between these two editions.

Here’s what we changed:

  • Updated all apps and exercises to .NET 7 (C# 11).
  • Added coverage of new features for working with…
    • global using directives
    • file-scoped namespaces
    • raw string literals
    • property patterns
    • structures and records
  • Thoroughly streamlined the book by removing outdated coding techniques and replacing them with today’s best practices.

What software your students need for this book

To develop the Windows Forms applications presented in this book, your students will need the following:

Windows 10 or later

Although .NET is cross-platform, you can’t use macOS or Linux to develop Windows Forms applications like the ones shown in this book. You have to use Windows 10, Version 1607 or later.

Visual Studio Community 2022 or later

The Community edition of Visual Studio can be downloaded for free from Microsoft’s website, and it includes all of the components needed to work with this book:

  • .NET
  • The compiler for the C# language
  • SQL Server Express LocalDB, an embedded version of the SQL Server database

Appendix A of the book shows your students how to install Visual Studio and its components on their own PCs.

What people say about this book

"Best C# book ever. Murach manuals are precise and to the point, with lots and lots of examples. Highly recommended for beginners."
- Posted at an online bookseller

"Murach has yet again hit a home run! This book is laid out in such a way where the theory is on the left page and the ‘Cliff Notes’ version of the content is on the right side. It gets you from zero to Jr Dev knowledge in no time. After the fact, you can always use that right page as a great reference whilst in the middle of a project. Bravo again, guys."
- Brian Knight, Founder, Pragmatic Works, Florida

"This is probably the best textbook I have ever used. It covers C# programming from the ground up and is outstanding. Useful information is emphasized and each section contains a summary for reinforcement. I am learning very fast. I have also heard from computer science grads that this author produces the best texts on many other programming languages."
- Posted at an online bookseller

"This book is awesome! I recommend it anyone new to programming like myself. Loved how the author used forms to teach the language. It was good for me because I got to see what I was making."
- Posted at an online bookseller

"A notable feature of the book is that everything is done as a ‘How to,’ which is great when you are learning. This is the typical Murach approach to books, making them not just useful for learning but also as big cookbooks."
- David Bolton, Past Host of C/C++/C# for About.com (now on ThoughtCo.com)

"I have trouble reading books (boring and I'm lazy) - the 'paired pages' approach is really nice - give it a try."
- Posted at an online bookseller

"Just trying to learn a development language can be daunting, and you can spend hours trying to find the answer to rather straightforward questions, like working with arrays. This book brings it all together in a comprehensive manner that is easy to understand and follow."
- Hal Hayes, Capital Area .NET User Group

"I can't express how much this book helps with explaining everything in detail. If you are just starting out in C# programming, this is the book I would suggest getting."
- Posted at an online bookseller

"I have learned more in the 800+ pages of this book than I have reading half a dozen other books and hours of forum posts online."
- Posted at an online bookseller

View the table of contents for this book in a PDF: Table of Contents (PDF)

Click on any chapter title to display or hide its content.

Section 1  An introduction to Visual Studio

Chapter 1  How to get started with Visual Studio

An introduction to .NET development

Platforms for .NET applications

Visual Studio and the .NET programming languages

The .NET Framework and .NET Core

The Visual Studio IDE

How a C# application is compiled and run

A tour of the Visual Studio IDE

How to start Visual Studio

How to open or close an existing project

How to use the Form Designer

How to use the Code Editor

How to use the Solution Explorer

How to work with Visual Studio’s windows

How to change the .NET version used by a project

How to test a project

How to build a project

How to run a project

Chapter 2  How to design a Windows Forms app

How to get started

How to create a new project

How to configure a new Windows Forms app

How to design a form

The design of the Invoice Total form

How to add controls to a form

How to set properties

Common properties for forms and controls

How to add navigation features

The property settings for the Invoice Total form

How to finish your design

How to rename the files of a project

How to save the files of a project

Chapter 3  How to code and test a Windows Forms app

An introduction to coding

Introduction to object-oriented programming

How to refer to properties, methods, and events

How an application responds to events

How to add code to a form

How to create an event handler for the default event of a form or control

How to delete an event handler

How IntelliSense helps you enter the code for a form

The event handlers for the Invoice Total form

How to detect and correct syntax errors

More coding skills

How to code with a readable style

How to code comments

How to work with the Text Editor toolbar

How to collapse or expand blocks of code

How to use code snippets

How to refactor code

How to get help information

How to run, test, and debug a project

How to run a project

How to test a project

How to debug runtime errors

Section 2  The C# language essentials

Chapter 4  How to work with numeric and string data

How to work with the built-in value types

The built-in value types

How to declare and initialize variables

How to declare and initialize constants

How to code arithmetic expressions

How to code assignment statements

How to work with the order of precedence

How to use casting

How to use the Math class

How to generate random numbers

How to work with strings

How to declare and initialize a string

How to join and append strings

How to include special characters in strings

How to code raw string literals

How to convert data types

The .NET structures and classes that define data types

How to use methods to convert data types

How to use methods to convert numbers to formatted strings

Four other skills for working with data

How to work with scope

How to declare and use enumerations

How to work with nullable value types and the null-coalescing operators

How to work with nullable reference types

Two versions of the Invoice Total app

The basic Invoice Total app

The enhanced Invoice Total app

Chapter 5  How to code control structures

How to code Boolean expressions

How to use the relational operators

How to use the logical operators

How to code conditional statements and expressions

How to code if-else statements

How to code switch statements

How to code switch expressions

How to use pattern matching

How to use the conditional operator

An enhanced version of the Invoice Total app

How to code loops

How to code while and do-while loops

How to code for loops

Loops that use break and continue statements

Debugging techniques for programs with loops

The Future Value app

The design and property settings for the form

The code for the form

Chapter 6  How to code methods and event handlers

How to code and call methods

How to code methods

How to call methods

How to use optional parameters

How to use named arguments

How to code expression-bodied methods

How to use refactoring to create a new method and its calling statement

When and how to pass arguments by reference and by value

How to work with tuples

How to create tuples and refer to their members

How to use a tuple as the return type for a method

How to work with events and delegates

How to generate an event handler for any event

How event wiring works

How to handle multiple events with one event handler

Another version of the Future Value app

The event handlers and the CalculateFutureValue() method

Some of the generated code

Chapter 7  How to handle exceptions and validate data

An introduction to exceptions

How exceptions work

How to display a dialog

How to use structured exception handling

How to catch an exception

How to use the properties and methods of an exception

How to catch specific types of exceptions

How to throw an exception

The Future Value app with exception handling

How to validate data

How to validate a single entry

How to code generic methods for data validation

How to validate multiple entries

The Future Value app with data validation

The dialogs

The code

Chapter 8  How to use arrays and collections

How to work with one-dimensional arrays

How to create an array

How to assign values to the elements of an array

How to work with arrays

How to use foreach loops to work with arrays

How to work with rectangular arrays

How to create a rectangular array

How to assign values to a rectangular array

How to work with rectangular arrays

More skills for working with arrays

How to use the Array class

How to refer to and copy arrays

How to code methods that work with arrays

How to use the null-conditional operator

More ways to refer to array elements

How to work with list patterns

How to work with collections

Commonly used collection classes

Typed vs. untyped collections

How to work with a list

How to work with a sorted list

How to work with queues and stacks

How to work with an array list

Chapter 9  How to work with dates and strings

How to work with dates and times

How to create a DateTime value

How to get the current date and time

How to format DateTime values

How to get information about dates and times

How to perform operations on dates and times

How to work with strings

The members of the String class

Code examples that work with strings

More code examples that work with strings

How to use interpolated strings for join operations

How to use the Parse() and TryParse() methods to validate numeric entries

How to use the StringBuilder class

How to format numbers, dates, and times

How to format numbers

How to format dates and times

How to use interpolated strings for formatting

Chapter 10  More skills for working with Windows forms and controls

How to work with controls

Five more types of controls

How to work with combo boxes and list boxes

How to work with check boxes and radio buttons

How to work with group boxes

How to use Tab Order view to set the tab order

How to get the information you need for using a control

How to work with multi-form projects

How to add a form to a project

The code that’s generated for a new form

How to work with global using directives

How to rename a form

How to display the first form of an app

How to display a form as a dialog

How to pass data between a form and a custom dialog

How to use the MessageBox class

How to display a dialog and get the user response

How to use the FormClosing event

The Payment app

The operation

The property settings

The code for the Customer form

The code for the Payment form

Chapter 11  How to debug an app

Basic debugging techniques

How to work in break mode

How to work with data tips

How to use the Hot Reload feature

How to use breakpoints

How to control the execution of an app

How to use the debugging windows

How to use the Locals window to monitor variables

How to use the Autos window to monitor variables

How to use Watch windows to monitor expressions

How to use the Immediate window to execute commands

How to use the Output window to view project information

How to write data to the Output window

How to use the Visualizer to view strings and collections

Section 3  Object-oriented programming

Chapter 12  How to create and use classes

An introduction to classes

How classes can be used to structure an app

How to define a class

How to create objects from a class

Basic skills for creating a class

How to add a class file to a project

How to code properties

How to code methods

How to code constructors

How to code static members

The Product Maintenance app

The operation of the Product Maintenance app

The classes used by the Product Maintenance app

The code for the Product Maintenance app

More skills for creating and using classes

How to code properties with fields

How to code overloaded methods and constructors

How to code required properties

How to use property patterns

How to create and use structures, records, and record structs

How to create a structure

How to use a structure

How to create and use a record

How to create and use a record struct

When to use classes, structures, records, and record structs

The Product Maintenance app updated to use a record

Chapter 13  How to work with indexers, delegates, events, and operators

An introduction to the ProductList class

The code for a simple ProductList class

The specifications for the enhanced ProductList class

How to work with indexers

How to create an indexer

How to code expression-bodied indexers and accessors

How to throw an argument exception

How to work with delegates and events

How to define and use a delegate

How to define and use events

How to use anonymous methods and lambda expressions with delegates and events

How to overload operators

An introduction to operator overloading

How to overload arithmetic operators

How to overload relational operators

An enhanced version of the Product Maintenance application

The code for the ProductList class

The code for the Product Maintenance form

Chapter 14  How to work with inheritance

An introduction to inheritance

How inheritance works

How .NET uses inheritance

Methods inherited from the System.Object class

How to use inheritance in your apps

Basic skills for working with inheritance

How to create a base class

How to create a subclass

How polymorphism works

An inheritance version of the Product Maintenance app

The operation of the Product Maintenance app

The code for the Product, Book, and Software classes

The code for the ProductList class

The code for the Product Maintenance form

The code for the New Product form

Object types and casting

How to use the Type class to get information about an object’s type

How to use casting with inheritance

How to work with abstract and sealed classes

How to work with abstract classes

How to work with sealed classes

Chapter 15  How to work with interfaces and generics

How to work with interfaces

An introduction to interfaces

Some of the interfaces defined by .NET

How to create an interface

How to work with default methods

How to work with static methods and fields

How to implement an interface

A Product class that implements the ICloneable interface

How to use an interface as a parameter

How to work with generics

How to code a class that defines a generic collection

Some of the generic interfaces defined by .NET

How to implement the IComparable interface

How to use constraints

How to implement the IEnumerable interface

How to code an interface that uses generics

Chapter 16  How to organize, document, and test your classes

How to organize your classes

How to code multiple classes in a single file

How to split a single class across multiple files

How to work with namespaces

How to work with file scoped namespaces

How to document your classes

How to add XML documentation to a class

How to view the XML documentation

How to create and use class libraries

How class libraries work

How to create a class library project

How to add a reference to a class library

How to use the classes in a class library

How to implement unit testing

How unit testing works

How to create a unit test project

How to code unit tests

How to run unit tests

Section 4  Basic skills for working with data

Chapter 17  How to work with file I/O

An introduction to the System.IO classes

The classes for managing directories, files, and paths

How files and streams work

How to use the FileStream class

How to use the exception classes for file I/O

How to work with text files

How to write a text file

How to read a text file

How to use the using statement and the using declaration

A class that works with a text file

How to work with binary files

How to write a binary file

How to read a binary file

A class that works with a binary file

Chapter 18  How to use LINQ

Basic concepts for working with LINQ

How LINQ is implemented

Advantages of using LINQ

The three stages of a query operation

How to code query expressions

How to identify the data source for a query

How to filter the results of a query

How to sort the results of a query

How to select fields from a query

How to join data from two or more data sources

How to code method-based queries

How to use the LINQ methods for query operations

How to use additional LINQ methods

A Customer Invoice application that uses generic lists

The user interface

The code for the form

Section 5  Database programming

Chapter 19  An introduction to database programming

An introduction to client/server systems

The hardware components of a client/server system

The software components of a client/server system

An introduction to relational databases

How a table is organized

How the tables in a database are related

How the columns in a table are defined

The design of the MMABooks database

How to use SQL to work with a relational database

How to query a single table

How to join data from two or more tables

How to add, update, and delete data in a table

Chapter 20  How to use Entity Framework Core

How to create a data model

How Entity Framework Core works

How to add EF Core to your project

How to generate DB context and entity classes

The data model for the MMABooks database

The code for the DB context class

The code for the Customer entity class

How to modify the generated code

How to use LINQ with EF Core

How to retrieve data

How to load related objects

How to use EF Core to modify a database

How to insert, update, and delete data

How to handle database exceptions

How concurrency affects insert, update, and delete operations

How to check for concurrency conflicts

How to handle concurrency exceptions

How to bind controls

How to bind controls to a collection

How to bind controls to the results of a query

How to code a data access class

A simple data access class

A data access class that handles exceptions

The Customer Maintenance app

The user interface

The code for the Customer Maintenance form

The code for the Add/Modify Customer form

Chapter 21  How to use ADO.NET to write your own data access code

An introduction to ADO.NET

The .NET data provider for SQL Server

How the connection, command, and data reader objects work

How to work with connections and commands

How to create and work with connections

How to create and work with commands

How to work with parameters

How to use parameters in SQL statements

How to create and work with the parameters for a command

How to execute commands

How to create and work with a data reader

How to execute queries that return a single value

How to execute action queries

The Customer Maintenance app

The user interface

The code for the data access class

Chapter 22  How to use the DataGridView control

How to display data in a DataGridView control

An introduction to the DataGridView control

How to set the functions provided by a DataGridView control

How to bind to a data source

How to code a method in a data access class that gets selected columns

How to format the columns

How to format the headers and alternating rows

How to work with columns and events

How to add and remove columns

How to work with the object that’s passed to an event handler

A Product Maintenance app

The user interface

The code for the Product Maintenance form

How to provide paging for a DataGridView control

The user interface for a form that provides for paging

The code that implements the paging

How to create a Master/Detail form

The user interface for a Master/Detail form

The code for the DTOs, data access class, and form

Appendix  

Appendix A  How to set up Windows for this book

How to install the files for this book

How to install Visual Studio

How to set up your system to use the database

The instructor’s materials that you can request from this site provide everything you need for an effective course.

Objectives

  • Help your students focus on the skills that they should master.

Test banks

  • Provide a way to test comprehension.
  • Can be imported to all modern LMSs.
  • Contain questions that are designed to test the skills described by the objectives for each chapter.
  • Use only multiple-choice test questions because they have the highest validity.

Extra exercises

  • Give your students a chance to gain valuable hands-on experience.
  • Encourage the students to complete the exercise on their own since the solutions aren’t available from our website (unlike the exercises that are printed in the book).
  • Can be used for practice and tests.

Projects

  • Ask your students to write, test, and debug applications from scratch.
  • Provide a range of difficulty levels.
  • Can be used for both practice and tests.

PowerPoint slides

  • Summarize the critical information presented in the book.
  • Start with the instructional objectives for each chapter.

For a detailed description of all the materials, please see the Instructor’s Summary PDF. And if you use the Canvas LMS, we also will be providing a Canvas course file that you can use to import all of these materials with just a few clicks.

On this page, we’ll be posting answers to the questions that come up most often about this book. So if you have any questions that you haven’t found answered here at our site, please email us. Thanks!

To view the corrections for this book in a PDF, just click on this link: View the corrections

Then, if you find any other errors, please email us so we can correct them in the next printing of the book. Thank you!

Murach college books and courseware since 1974