Skip to main content

Über dieses Buch

This book presents the C# 5.0 language in a uniquely succinct and visual format. Often in programming books, the information can be hidden in a vast sea of words. As a programmer who has over the years used a dozen programming languages, the author understands it can sometimes be difficult to slog through another 1,000-page book of dense text to learn a new language. There are likely many other programmers who feel the same way. To address this situation, this book explains C# 5.0 using figures; short, focused code samples; and clear, concise explanations.

Figures are of prime importance in this book. While teaching programming seminars, Daniel Solis found that he could almost watch the light bulbs going on over the students’ heads as he drew the figures on the whiteboard. In this text, he has distilled each important concept into simple but accurate illustrations. The visual presentation of the content will give you an understanding of C# that’s not possible with text alone.

For something as intricate and precise as a programming language, however, there must be text as well as figures. But rather than long, wordy explanations, Solis has used short, concise descriptions and bulleted lists to make each important piece of information visually distinct.

By the end of this book, you’ll have a thorough working knowledge of all aspects of the C# language, whether you’re a novice programmer or a seasoned veteran of other languages. If you want a long, leisurely, verbose explanation of the language, this is not the book for you. But if you want a concise, thorough, visual presentation of C# 5.0, this is just what you’re looking for.



Chapter 1. C# and the .NET Framework

The C# programming language was designed for developing programs for Microsoft’s .NET Framework. This chapter gives a brief look at where .NET came from and its basic architecture. To start off, let’s get the name right: C# is pronounced “see sharp.”

Daniel M. Solis

Chapter 2. Overview of C# Programming

This chapter lays the groundwork for studying C#. Since I’ll use code samples extensively throughout the text, I first need to show you what a C# program looks like and what its various parts mean.

Daniel M. Solis

Chapter 3. Types, Storage, and Variables

If you were to broadly characterize the source code of C and C++ programs, you might say that a C program is a set of functions and datatypes and that a C++ program is a set of functions and classes. A C# program, however, is a set of type declarations.

The source code of a C# program or DLL is a set of one or more type declarations.

For an executable, one of the types declared must be a class that includes a method called Main.



is a way of grouping a related set of type declarations and giving the group a name. Since your program is a related set of type declarations, you will generally declare your program type inside a namespace you create.

Daniel M. Solis

Chapter 4. Classes: The Basics

In the previous chapter, you saw that C# provides six user-defined types. The most important of these, and the one I’ll cover first, is the


. Since the topic of classes in C# is a large one, I’ll spread its discussion over the next several chapters.

Daniel M. Solis

Chapter 5. Methods



is a block of code with a name. You can execute the code from somewhere else in the program by using the method’s name. You can also pass data into a method and receive data back as output.

Daniel M. Solis

Chapter 6. More About Classes

The previous two chapters covered two of the nine types of class members: fields and methods. In this chapter, I’ll introduce all the other class members except events and operators, and explain their features. I’ll cover events in Chapter 14.

Daniel M. Solis

Chapter 7. Classes and Inheritance

Inheritance allows you to define a new class that incorporates and extends an already declared class.

You can use an existing class, called the base class, as the basis for a new class, called the derived class. The members of the derived class consist of the following:

The members in its own declaration

The members of the base class

To declare a derived class, you add a class-base specification after the class name. The class-base specification consists of a colon, followed by the name of the class to be used as the base class. The derived class is said to directly inherit from the base class listed.

A derived class is said to extend its base class, because it includes the members of the base class plus any additional functionality provided in its own declaration.

A derived class

cannot delete

any of the members it has inherited.

Daniel M. Solis

Chapter 8. Expressions and Operators

This chapter defines expressions and describes the operators provided by C#. It also explains how you can define the C# operators to work with your user-defined classes.

Daniel M. Solis

Chapter 9. Statements

The statements in C# are very similar to those of C and C++. This chapter covers the characteristics of the C# statements, as well as the flow-of-control statements provided by the language.



a source code instruction describing a type or telling the program to perform an action.

There are three major categories of statements:

Declaration statements

: Statements that declare types or variables

Embedded statements

: Statements that perform actions or manage flow of control

Labeled statements

: Statements to which control can jump

Daniel M. Solis

Chapter 10. Structs

Structs are programmer-defined data types, very similar to classes. They have data members and function members. Although structs are similar to classes, there are a number of important differences. The most important ones are the following:

Classes are reference types, and structs are value types.

Structs are implicitly sealed, which means they cannot be derived from.

Daniel M. Solis

Chapter 11. Enumerations

An enumeration, or enum, is a programmer-defined type, such as a class or a struct.

Like structs, enums are value types and therefore store their data directly, rather than separately, with a reference and data.

Enums have only one type of member: named constants with integer values.

Daniel M. Solis

Chapter 12. Arrays

An array is a set of uniform data elements represented by a single variable name. The individual elements are accessed using the variable name together with one or more indexes between square brackets, as shown here:

Daniel M. Solis

Chapter 13. Delegates

You can think of a delegate as an object that holds one or more methods. Normally, of course, you wouldn’t think of “executing” an


, but a delegate is different from a typical object. You can execute a delegate, and when you do so, it executes the method or methods that it “holds.”

Daniel M. Solis

Chapter 14. Events

One common requirement in many programs is that when a particular program event occurs, other parts of the program need to be notified that the event has occurred.

Daniel M. Solis

Chapter 15. Interfaces



is a reference type that

specifies a set of function members

but does not implement them. That’s left to classes and structs that

implement the interface

. This description sounds pretty abstract, so let me first show you the problem that an interface helps solve, and how it solves it.

Daniel M. Solis

Chapter 16. Conversions

To get an understanding of what conversions are, let’s start by considering the simple case in which you declare two variables of different types and then assign the value of one (the


) to the other (the


). Before the assignment can occur, the source value must be converted to a value of the target type. Figure 16-1 illustrates type conversion.


is the process of taking a value of one type and

using it as

the equivalent value of another type.

The value resulting from the conversion should be the same as the source value—but in the target type.

Daniel M. Solis

Chapter 17. Generics

With the language constructs you’ve learned so far, you can build powerful objects of many different types. You do this mostly by declaring classes that encapsulate the behavior you want and then creating instances of those classes.

Daniel M. Solis

Chapter 18. Enumerators and Iterators

In Chapter 12, you saw that you can use a f oreach statement to cycle through the elements of an array. In this chapter, you’ll take a closer look at arrays and see why they can be processed by f oreach statements. You’ll also look at how you can add this capability to your own user-defined classes, using iterators.

Daniel M. Solis

Chapter 19. Introduction to LINQ

In a relational database system, data is organized into nicely normalized tables and accessed with a very simple but powerful query language—SQL. SQL can work with any set of data in a database because the data is organized into tables, following strict rules.

Daniel M. Solis

Chapter 20. Introduction to Asynchronous Programming

When you start a program, the system creates a new


in memory. A process is the set of resources that comprise a running program. These include the virtual address space, file handles, and a host of other things required for the program to run.

Daniel M. Solis

Chapter 21. Namespaces and Assemblies

In Chapter 1, we took a high-level look at the compilation process. You saw that the compiler takes the source code file and produces an output file called an


. This chapter takes a closer look at assemblies and how they are produced and deployed. It also covers how namespaces help organize types.

Daniel M. Solis

Chapter 22. Exceptions



is a runtime error in a program that violates a system or application constraint, or a condition that is not expected to occur during normal operation. Examples are when a program tries to divide a number by zero or tries to write to a read-only file. When these occur, the system catches the error and


an exception.

Daniel M. Solis

Chapter 23. Preprocessor Directives

The source code specifies the definition of a program. The

preprocessor directives

instruct the compiler how to treat the source code. For example, under certain conditions, you might want the compiler to ignore portions of the code, and under other conditions, you might want that code compiled. The preprocessor directives give you those options and several others.

Daniel M. Solis

Chapter 24. Reflection and Attributes

Most programs are written to work on data. They read, write, manipulate, and display data. (Graphics are a form of data.) For some types of programs, however, the data they manipulate is not numbers, text, or graphics, but information about programs and program types.

Data about programs and their classes is called metadata and is stored in the programs’ assemblies.

A program can look at the metadata of other assemblies or of itself, while it’s running. When a running program looks at its own metadata, or that of other programs, it’s called reflection.

Daniel M. Solis

Chapter 25. Other Topics

In this chapter, I’ll cover a number of other topics that are important in using C# but that don’t fit neatly into one of the other chapters. These include string handling, nullable types, the Main method, documentation comments, and nested types.

Daniel M. Solis


Weitere Informationen

Premium Partner

Neuer Inhalt

BranchenIndex Online

Die B2B-Firmensuche für Industrie und Wirtschaft: Kostenfrei in Firmenprofilen nach Lieferanten, Herstellern, Dienstleistern und Händlern recherchieren.



Product Lifecycle Management im Konzernumfeld – Herausforderungen, Lösungsansätze und Handlungsempfehlungen

Für produzierende Unternehmen hat sich Product Lifecycle Management in den letzten Jahrzehnten in wachsendem Maße zu einem strategisch wichtigen Ansatz entwickelt. Forciert durch steigende Effektivitäts- und Effizienzanforderungen stellen viele Unternehmen ihre Product Lifecycle Management-Prozesse und -Informationssysteme auf den Prüfstand. Der vorliegende Beitrag beschreibt entlang eines etablierten Analyseframeworks Herausforderungen und Lösungsansätze im Product Lifecycle Management im Konzernumfeld.
Jetzt gratis downloaden!