Amazon.co.uk Review
It's no secret that many computer books are pretty much devoid of an authorial personality. This title is a winning exception. The author is able to weave in clever examples (using such topics as his own long experience in computing, his dog, Star Trek, etc.) without being coy or getting in the way of presenting real technical information. Liberty's wide experience in computers and general writing skill shows, as he is able to draw on a wealth of examples to move his text forward.
These are a couple of goals at work in Programming C#. First, it's an excellent language tutorial, certainly one of the smartest and best available guides to C# as a language. Early chapters explore basic and obscure language options using inheritance, delegation, interface and the conventions in C# used to implement these techniques. The middle part of the book turns toward the .NET Framework itself, with two useful (and somewhat introductory) chapters on both Windows Forms and Web Forms, for standalone and Web-based applications, respectively.
Later sections crank up the technical knowledge again with several advanced topics on understanding .NET assemblies and deployment in detail, as well as "reflection" APIs that allow .NET programs to essentially modify their code at run time. (One technique, reflection emit, that literally writes bytecodes, will definitely interest expert readers, though it's unlikely most programmers will need to do this.) Final sections look at the .NET stream classes (rivalled only by Java's for complexity). Liberty looks at basic file and network I/O as well as how objects get serialised and marshalled both for SOAP and Web services and "normal" .NET remoting.
The author's sure hand here in navigating the difficult waters of C# and .NET makes for a relatively concise text that is chock-full of useful information on C#. Filled with notably clever and inventive examples, this book is possibly the veteran computer author's best title to date, and it's sure to be a noteworthy resource as experienced developers tackle C# for the first time. --Richard Dragan --This text refers to an out of print or unavailable edition of this title.
Review
Jeff Richards, Windowatch, June 2002
Salt Lake City ColdFusion User Group, June 2002
Thomas Paul, JavaRanch.com, July 2002
Product Description
C# was designed from the ground up for development on Microsoft's .NET framework. As such, it's a high-performance language that's simple, safe, object-oriented, and Internet-centric. Programming C#, 3rd Edition teaches this new language in a way that experienced programmers will appreciate--by grounding its applications firmly in the context of Microsoft's .NET platform and the development of desktop and Internet applications.
Bestselling author Jesse Liberty has updated this latest edition to reflect the release of Visual Studio .NET 2003 and the .NET Framework 1.1. He's also added an entirely new chapter demonstrating various web forms and web services applications, and enlarged and expanded his coverage of events and delegates in response to numerous reader requests. He's even added tips for programmers coming from VB and C++ backgrounds.
The first part of this book introduces C# fundamentals, then goes on to explain:
- Classes and objects
- Inheritance and polymorphism
- Operator overloading
- Structs and interfaces
- Arrays, indexers, and collections
- String objects and regular expressions
- Exceptions and bug handling
- Delegates and events
Part three gets to the heart of the .NET Framework, focusing on attributes and reflection, remoting, threads and synchronization, and streams. Part three also illustrates how to interoperate with COM objects.
In much the way that you can see the features and personality of the parents and grandparents in young children, you can easily see the influence of Java, C++, Visual Basic, and other languages in C#. The level of information in Programming C#, 3rd Edition allows you to become productive quickly with C# and to rely on it as a powerful addition to your family of mastered programming languages.
From the Publisher
Adult birds stand about three feet tall and weigh six to nine pounds. Inside their long necks is a five-foot long windpipe-part of which is coiled inside their breastbone-giving voice to loud calls that can carry for miles. They live for about 22 years, spending most of their waking hours looking for the various plants, small animals, and insects they like to eat. (One crowned crane food-finding technique, perfected during the 38 to 54 million years these birds have been around, is to stamp their feet as they walk, flushing out tasty bugs.) They are the only type of crane to perch in trees, which they do at night when sleeping.
Social and talkative, African crowned cranes group together in pairs or families, and the smaller groups band together in flocks of more than 100 birds. Their elaborate mating dance has served as a model for some of the dances of local groups of people.
Darren Kelly was the production editor and Audrey Doyle was the proofreader for Programming C#. Mary Brady and Claire Cloutier provided quality control. Joe Wizda wrote the index. Interior composition was done by James Carter, Matthew Hutchinson, and Edith Shapiro.
Ellie Volckhausen designed the cover of this book, based on a series design by Edie Freedman. The cover image is an original antique engraving from the 19th century. Emma Colby produced the cover layout with QuarkXPress 4.1 using Adobe's ITC Garamond font.
David Futato designed the interior layout based on a series design by Nancy Priest. Neil Walls converted the files from Microsoft Word to FrameMaker 5.5.6 using tools created by Mike Sierra. The text and heading fonts are ITC Garamond Light and Garamond Book; the code font is Constant Willison. The illustrations that appear in this book were produced by Robert Romano and Jessamyn Read using Macromedia FreeHand 9 and Adobe Photoshop 6. This colophon was written by Leanne Soylemez.
Our look is the result of reader comments, our own experimentation, and feedback from distribution channels. Distinctive covers complement our distinctive approach to technical topics, breathing personality and life into potentially dry subjects. --This text refers to an out of print or unavailable edition of this title.
About the Author
Jesse Liberty is the best selling author of Programming ASP.NET, Programming C#, and a dozen other books on web and object oriented programming. He is president of Liberty Associates, Inc., where he provides contract programming, consulting and on-site training in ASP.NET, C#, C++ and related topics. Jesse has been a Distinguished Software Engineer at AT&T and Vice President for technology development at CitiBank.
Excerpted from Programming C# by Jesse Liberty. Copyright © 2003. Reprinted by permission. All rights reserved.
When a head of state dies, the president of the United States typically does not have time to attend the funeral personally. Instead, he dispatches a delegate. Often this delegate is the vice president, but sometimes the VP is unavailable and the president must send someone else, such as the secretary of state or even the first lady. He does not want to "hardwire" his delegated authority to a single person; he might delegate this responsibility to anyone who is able to execute the correct international protocol.
The president defines in advance what responsibility will be delegated (attend the funeral), what parameters will be passed (condolences, kind words), and what value he hopes to get back (good will). He then assigns a particular person to that delegated responsibility at "runtime" as the course of his presidency progresses.
In programming, you are often faced with situations where you need to execute a particular action, but you dont know in advance which method, or even which object, youll want to call upon to execute it. For example, a button might know that it must notify some object when it is pushed, but it might not know which object or objects need to be notified. Rather than wiring the button to a particular object, you will connect the button to a delegate and then resolve that delegate to a particular method when the program executes.
In the early, dark, and primitive days of computing, a program would begin execution and then proceed through its steps until it completed. If the user was involved, the interaction was strictly controlled and limited to filling in fields.
Todays Graphical User Interface (GUI) programming model requires a different approach, known as event-driven programming. A modern program presents the user interface and waits for the user to take an action. The user might take many different actions, such as choosing among menu selections, pushing buttons, updating text fields, clicking icons, and so forth. Each action causes an event to be raised. Other events can be raised without direct user action, such as events that correspond to timer ticks of the internal clock, email being received, file-copy operations completing, etc.
An event is the encapsulation of the idea that "something happened" to which the program must respond. Events and delegates are tightly coupled concepts because flexible event handling requires that the response to the event be dispatched to the appropriate event handler. An event handler is typically implemented in C# as a delegate.
Delegates are also used as callbacks so that one class can say to another "do this work and when youre done, let me know."
Delegates
In C#, delegates are first-class objects, fully supported by the language. Technically, a delegate is a reference type used to encapsulate a method with a specific signature and return type. You can encapsulate any matching method in that delegate.
In C++ and many other languages, you can accomplish this requirement with function pointers and pointers to member functions. Unlike function pointers, delegates are object-oriented and type safe.
A delegate is created with the delegate keyword, followed by a return type and the signature of the methods that can be delegated to it, as in the following:
public delegate int WhichIsFirst(object obj1, object obj2);
This declaration defines a delegate named WhichIsFirst, which will encapsulate any method that takes two objects as parameters and that returns an int.
Once the delegate is defined, you can encapsulate a member method with that delegate by instantiating the delegate, passing in a method that matches the return type and signature. The delegate can then be used to invoke that encapsulated method.
Using Delegates to Specify Methods at Runtime
Delegates uncouple the class that declares the delegate from the class that uses the delegate. For example, suppose that you want to create a simple container class called a Pair that can hold and sort any two objects passed to it. You cant know in advance what kind of objects a Pair will hold, but by creating methods within those objects to which the sorting task can be delegated, you can delegate responsibility for determining their order to the objects themselves.
Different objects will sort differently (for example, a Pair of Counter objects might sort in numeric order, while a Pair of Buttons might sort alphabetically by their name). As the author of the Pair class, you want the objects in the pair to have the responsibility of knowing which should be first and which should be second. To accomplish this, you will insist that the objects to be stored in the Pair must provide a method that tells you how to sort the objects.
You can define this requirement with interfaces, as well. Delegates are smaller and of finer granularity than interfaces. The Pair class does not need to implement an entire interface, it just needs to define the signature and return type of the method it wants to invoke. That is what delegates are for: they define the return type and signature of methods that can be invoked through the interface.
In this case, the Pair class will declare a delegate named WhichIsFirst. When the Pair needs to know how to order its objects, it will invoke the delegate passing in its two member objects as parameters. The responsibility for deciding which of the two objects comes first is delegated to the method encapsulated by the delegate.
public delegate Comparison
WhichIsFirst(object obj1, object obj2);
In this definition, WhichIsFirst is defined to encapsulate a method that takes two objects as parameters, and that returns an object of type Comparison. Comparison turns out to be an enumeration you will define:
public enum Comparison
{
theFirstComesFirst = 1,
theSecondComesFirst = 2
}