C#

The Bonus Site for C# 2008 For Dummies
csharp102.info

NEW ON THE SITE! Click here.

Welcome

If my book, C# 2008 For Dummies, is "C# 101," then this site is "C# 102." This site C# 2008 For Dummies Book Coveris dedicated to supporting the book by providing lots of extras.

The 2008 edition updates the previous edition (2005) --
but more than that, it's heavily revised to add more C# info for you! What's really hot in this edition? See the section What's Hot in the New C# 3.0? below.

(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 over the next few months. 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#, see especially Chapters 15, 16, and 17 in the Table of Contents and take a look at the "What's Hot" section below.

What's hot in the new C# 3.0?

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.

*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