C#

The Bonus Site for C# 2008 For Dummies and C# 2010 All-In-One For Dummies
csharp102.info

New on the Site - Click here.

Learn Test-Driven Development (TDD): Now brand new: 250 pages of FREE tutorial and code.

Welcome to 102

C# 2010 All-In-One For Dummies C# 2008 For Dummies

If my book, C# 2008 For Dummies, is "C# 101," then this site is "C# 102" (and the newest edition, C# 2010 All-In-One For Dummies is C# 103!) This site is dedicated to supporting the book by providing lots of extras. I try to update the site frequently, adding mainly articles and new C# code. See the link at the top right of this page to NEW ON THE SITE.

The 2008 edition updates the previous edition (2005) and the 2010 edition updates the 2008 edition (funny how these things go)--
but more than that, both books are heavily revised to add more C# info for you! What's really hot in this edition? See the sections What's Hot in the New C# 3.0? and What's Hot in the Newer C# 4.0 below.

For a table mapping chapters in the 2010 edition to the 2008 edition, click here.

(Note about page display. See bottom of page.*)

For Beginners | For Experienced Programmers

What's on the site

I'll be adding new content gradually as I get it developed. Note that this site contains extra materials, but you can also go to www.dummies.com to find information about lots of other For Dummies programming books.

Go to Top

For beginners

This section is for those new to C#, or even new to programming.

C# is a programming language -- a specialized "language" for writing programs, sets of instructions for the computer to carry out. C# has been around now for some six or seven years, a part of Microsoft's .NET initiative. .NET amounts to the current way to program for Windows. C# is based on earlier languages, including Java, C, and C++. C# programs consist of objects that communicate with each other, supplying services to each other.

 

An example

Programs contain a structured sequence of statements; each statement stores data in a variable, or makes a decision, or manipulates some data. An object-oriented program (OOP) packages bits of data into objects, such as a Student object in a school management program. Objects also know how to operate on their own data. For example, a Student object might call upon an I/O object to write its information into a permanent disk file.

To illustrate, a program representing a game of tic tac toe might consist of a Game object to manage the players and their turn-taking, a Board object to store information about where the Xs and Os have been placed, and so on.

Some C# codeEvery program starts off in a Main method, so for the tic tac toe game, Main might create a Game object and call its Play method, which would wait for the first (human) player to mark an X in a square, then record that X in the Board object and see if that might have been a winning move. Then Play would wait for the O player, and so on, back and forth in a loop until one player wins -- or the Board fills up without either player having won.

Go to Top

For experienced coders coming to C#

This section is for those with programming experience, maybe even previous C# experience, who want to learn C# or find out what's new in the latest version. If you're new to C#, be sure to check out the annotated Table of Contents. If you already know some C#, take a look at the "What's Hot" sections for C# 2008 and C# 2010 below.

What's hot in the new C# 3.0 (2008)?

Well, suppose you have an array of numbers { 0, 2, 4, 7, 3, 9 } and you'd like to pick out the even numbers in the array, resulting in a new array containing just 0, 2, and 4. With a simple "query" expression, you can get that list -- no need for a loop. You just specify your query with the new Language Integrated Query (LINQ) functionality in C#. Chapter 17 in the book takes you through writing some pretty cool LINQ queries on data in C# arrays and collections. You can even write very similar queries with LINQ on data in databases or in Extensible Markup Language (XML) files (although we don't cover database or XML topics in the book). Here's the even-numbers query I mentioned above:

var evens = from n in numbers
where n % 2 == 0
select n;

Go to Top

Other new features

The book covers these topics except for the two that contain links to outside information.

  • The new var keyword, which tells the compiler to infer the data type of a result variable based on the expression being assigned.
  • Compact ways to initialize arrays, collections, and objects with properties.
  • Extension methods -- adding methods to existing classes without subclassing and without access to the classes' source code.
  • Lambda expressions -- compact replacements for delegates and anonymous methods.
  • Anonymous types -- create on-the-fly classes without writing them explicitly. Let the compiler do it.
  • Expression trees -- representations of C# expressions as data. You can then pass the trees to some expression processor, such as one that generates Structured Query Language (SQL) commands to send to a database engine.
  • Partial methods -- method definitions for which you can postpone writing the bodies.
  • Application of query expressions for database and XML data.

What's Hot in the Newer C# 4.0 (2010)?

C# 4.0 adds new features that help you:

  • Program dynamically with the new dynamic keyword (see next topic).
  • Carry out code interoperation with old-fashioned COM objects (still very much in use), including the COM objects that make up Microsoft Office's object models that you can use to operate Word, Excel, and other Office apps from your code. See the new dynamic keyword in Chapters 1 & 3 in Book VIII of C# 2010 All-In-One For Dummies.
  • Use C#'s generic features in a more complete way given their new covariance and contravariance. See Chapter 4 in Book VIII of C# 2010 All-In-One For Dummies.

*Page Display Note: If you get browser messages about blocking scripts or ActiveX controls from running on the page, please know that these pages contain no harmful code.

Go to Top