Professional C# 4.0 and .NET 4

( 8 )

Overview

"This book starts by reviewing the overall architecture of .NET in order to give you the background you need to be able to write managed code. After that, the book is divided into a number of sections that cover both the C# language and its application in a variety of areas." "Part I: The C# Language: This section gives a good grounding in the C# language itself. This section doesn t presume knowledge of any particular language, although it does assume you are an experienced programmer. You start by looking at C's basic syntax and data types, and ...

See more details below
Paperback
$39.58
BN.com price
(Save 34%)$59.99 List Price
Other sellers (Paperback)
  • All (23) from $7.43   
  • New (16) from $14.69   
  • Used (7) from $7.43   
Professional C# 4.0 and .NET 4

Available on NOOK devices and apps  
  • NOOK Devices
  • NOOK HD/HD+ Tablet
  • NOOK
  • NOOK Color
  • NOOK Tablet
  • Tablet/Phone
  • NOOK for Windows 8 Tablet
  • NOOK for iOS
  • NOOK for Android
  • NOOK Kids for iPad
  • PC/Mac
  • NOOK for Windows 8
  • NOOK for PC
  • NOOK for Mac
  • NOOK Study
  • NOOK for Web

Want a NOOK? Explore Now

NOOK Book (eBook)
$34.49
BN.com price
(Save 42%)$59.99 List Price

Overview

"This book starts by reviewing the overall architecture of .NET in order to give you the background you need to be able to write managed code. After that, the book is divided into a number of sections that cover both the C# language and its application in a variety of areas." "Part I: The C# Language: This section gives a good grounding in the C# language itself. This section doesn t presume knowledge of any particular language, although it does assume you are an experienced programmer. You start by looking at C's basic syntax and data types, and then explore the object-oriented features of C# before moving on to look at more advanced C# programming topics. Objects, types, inheritance, generics, arrays, tuples, operators, casts, delegates, lambdas, events, strings, regular expressions, collections, Language Integrated, Query (LINQ), Dynamic Language Extensions, memory management, pointers, reflection, errors, and exception are all covered in part 1." "Part II: Visual Studio: This section looks at the main IDE utilized by C# developers worldwide: Visual Studio 2010. The two chapters in this section look at the best way to use the tool to build applications based on the .NET Framework 4. In addition, this section also focuses on the deployment of your projects." "Part III: Foundation: In this section, you look at the principles of programming in the .NET environment. In particular, you look at assemblies, instrumentation, security, threading, tasks, synchronization, localization, System.Transactions, networking, interop, XAML, Managed Extensibility Framework, Manipulating Files and the Registry, transactions, how to build Windows services, and how togenerate your own libraries as assemblies, among other topics." "Part IV: Data: Here, you look at accessing databases with ADO.NET, ADO.NET Entity Framework, data services. This part also extensively covers support in .NET for XML and on the Windows operating system side, and the .NET features of SQL Server 2008." "Part V: Presentation: This section shows how to build applications based upon the Windows Presentation Foundation and Silverlight, and covers writing components that will run on web sites, serving up web pages. It also has coverage on building classic Windows applications, which are called Windows Forms in .NET. Windows Forms are the thick-client version of applications, and using .NET to build these types of applications is a quick and easy way of accomplishing this task. Finally, it includes coverage of the tremendous number of features that ASP.NET, ASP.NET MVC, and ASP.Net Dynamic Data provide." "Part VI: Communication: This section is all about communication. It covers services for platform-independent communication using the Windows Communication Foundation (WCF). With Message Queuing, asynchronous disconnected communication is shown. This section looks at utilizing the Windows Workflow Foundation 4, as well as peer to peer networking, and creating syndication feeds." "The book closes with an appendix covering Windows 7 and Windows Server 2008 R2 development." Online Chapters: Even with such a large book, we can't fit in everything we'd like to tell you about C# and using this language with other .NET technologies, so we've made ten additional chapters available online at wrox.com. These chapters include information on a variety of topics: GDI+, which is a technology that is used for building applications that include advanced graphics; .Visual Studio Tools for Office (VSTO); NET Remoting for communication between .NET clients and servers; Enterprise Services for the services in the background; web services with ASP.NET, LINQ to SQL, Windows Workflow Foundation 3.0, and the Managed Add-In Framework (MAF). It also includes examples showing .NET 4 in others supported languages including Visual Basic, C++/CLI, and F#.

Read More Show Less

Product Details

  • ISBN-13: 9780470502259
  • Publisher: Wiley
  • Publication date: 3/30/2010
  • Edition number: 1
  • Pages: 1536
  • Sales rank: 392,391
  • Product dimensions: 7.30 (w) x 9.10 (h) x 2.00 (d)

Read an Excerpt

Professional C# 4.0 and .NET 4


By Christian Nagel Bill Evjen Jay Glynn Karli Watson Morgan Skinner

John Wiley & Sons

Copyright © 2010 John Wiley & Sons, Ltd
All right reserved.

ISBN: 978-0-470-50225-9


Chapter One

.NET Architecture

WHAT'S IN THIS CHAPTER?

* Compiling and running code that targets .NET

* Advantages of Microsoft Intermediate Language (MSIL)

* Value and reference types

* Data typing

* Understanding error handling and attributes

* Assemblies, .NET base classes, and namespaces

Throughout this book, we emphasize that the C# language must be considered in parallel with the .NET Framework, rather than viewed in isolation. The C# compiler specifically targets .NET, which means that all code written in C# will always run within the .NET Framework. This has two important consequences for the C# language:

1. The architecture and methodologies of C# reflect the underlying methodologies of .NET.

2. In many cases, specific language features of C# actually depend on features of .NET, or of the .NET base classes.

Because of this dependence, it is important to gain some understanding of the architecture and methodology of .NET before you begin C# programming. That is the purpose of this chapter.

THE RELATIONSHIP OF C# TO .NET

C# is a relatively new programming language and is significant in two respects:

* It is specifically designed and targeted for use with Microsoft's .NET Framework (a feature-rich platform for the development, deployment, and execution of distributed applications).

* It is a language based on the modern object-oriented design methodology, and, when designing it, Microsoft learned from the experience of all the other similar languages that have been around since object-oriented principles came to prominence some 20 years ago.

One important thing to make clear is that C# is a language in its own right. Although it is designed to generate code that targets the .NET environment, it is not itself part of .NET. Some features are supported by .NET but not by C#, and you might be surprised to learn that some features of the C# language are not supported by .NET (for example, some instances of operator overloading)!

However, because the C# language is intended for use with .NET, it is important for you to have an understanding of this Framework if you want to develop applications in C# effectively. Therefore, this chapter takes some time to peek underneath the surface of .NET. Let's get started.

THE COMMON LANGUAGE RUNTIME

Central to the .NET Framework is its runtime execution environment, known as the Common Language Runtime (CLR) or the .NET runtime. Code running under the control of the CLR is often termed managed code.

However, before it can be executed by the CLR, any source code that you develop (in C# or some other language) needs to be compiled. Compilation occurs in two steps in .NET:

1. Compilation of source code to Microsoft Intermediate Language (IL).

2. Compilation of IL to platform-specific code by the CLR.

This two-stage compilation process is very important, because the existence of the Microsoft Intermediate Language is the key to providing many of the benefits of .NET.

IL shares with Java byte code the idea that it is a low-level language with a simple syntax (based on numeric codes rather than text), which can be very quickly translated into native machine code. Having this well-defined universal syntax for code has significant advantages: platform independence, performance improvement, and language interoperability.

Platform Independence

First, platform independence means that the same file containing byte code instructions can be placed on any platform; at runtime, the final stage of compilation can then be easily accomplished so that the code will run on that particular platform. In other words, by compiling to IL you obtain platform independence for .NET, in much the same way as compiling to Java byte code gives Java platform independence.

Note that the platform independence of .NET is only theoretical at present because, at the time of writing, a complete implementation of .NET is available only for Windows. However, a partial implementation is available (see, for example, the Mono project, an effort to create an open source implementation of .NET, at www.go-mono.com).

Performance Improvement

Although we previously made comparisons with Java, IL is actually a bit more ambitious than Java byte code. IL is always Just-in-Time compiled (known as JIT compilation), whereas Java byte code was often interpreted. One of the disadvantages of Java was that, on execution, the process of translating from Java byte code to native executable resulted in a loss of performance (with the exception of more recent cases, where Java is JIT compiled on certain platforms).

Instead of compiling the entire application in one go (which could lead to a slow startup time), the JIT compiler simply compiles each portion of code as it is called (just in time). When code has been compiled once, the resultant native executable is stored until the application exits so that it does not need to be recompiled the next time that portion of code is run. Microsoft argues that this process is more efficient than compiling the entire application code at the start, because of the likelihood that large portions of any application code will not actually be executed in any given run. Using the JIT compiler, such code will never be compiled.

This explains why we can expect that execution of managed IL code will be almost as fast as executing native machine code. What it does not explain is why Microsoft expects that we will get a performance improvement. The reason given for this is that, because the final stage of compilation takes place at runtime, the JIT compiler will know exactly what processor type the program will run on. This means that it can optimize the final executable code to take advantage of any features or particular machine code instructions offered by that particular processor.

Traditional compilers will optimize the code, but they can only perform optimizations that are independent of the particular processor that the code will run on. This is because traditional compilers compile to native executable code before the software is shipped. This means that the compiler does not know what type of processor the code will run on beyond basic generalities, such as that it will be an x86-compatible processor or an Alpha processor.

Language Interoperability

The use of IL not only enables platform independence, it also facilitates language interoperability. Simply put, you can compile to IL from one language, and this compiled code should then be interoperable with code that has been compiled to IL from another language.

You are probably now wondering which languages aside from C# are interoperable with .NET; the following sections briefly discuss how some of the other common languages fit into .NET.

Visual Basic 2010

Visual Basic .NET 2002 underwent a complete revamp from Visual Basic 6 to bring it up to date with the first version of the .NET Framework. The Visual Basic language itself had dramatically evolved from VB6, and this meant that VB6 was not a suitable language for running .NET programs. For example, VB6 is heavily integrated into Component Object Model (COM) and works by exposing only event handlers as source code to the developer - most of the background code is not available as source code. Not only that, it does not support implementation inheritance, and the standard data types that Visual Basic 6 uses are incompatible with .NET.

Visual Basic 6 was upgraded to Visual Basic .NET in 2002, and the changes that were made to the language are so extensive you might as well regard Visual Basic as a new language. Existing Visual Basic 6 code does not compile to the present Visual Basic 2010 code (or to Visual Basic .NET 2002, 2003, 2005, and 2008 for that matter). Converting a Visual Basic 6 program to Visual Basic 2010 requires extensive changes to the code. However, Visual Studio 2010 (the upgrade of Visual Studio for use with .NET) can do most of the changes for you. If you attempt to read a Visual Basic 6 project into Visual Studio 2010, it will upgrade the project for you, which means that it will rewrite the Visual Basic 6 source code into Visual Basic 2010 source code. Although this means that the work involved for you is heavily cut down, you will need to check through the new Visual Basic 2010 code to make sure that the project still works as intended because the conversion might not be perfect.

One side effect of this language upgrade is that it is no longer possible to compile Visual Basic 2010 to native executable code. Visual Basic 2010 compiles only to IL, just as C# does. If you need to continue coding in Visual Basic 6, you can do so, but the executable code produced will completely ignore the .NET Framework, and you will need to keep Visual Studio 6 installed if you want to continue to work in this developer environment.

Visual C++ 2010

Visual C++ 6 already had a large number of Microsoft-specific extensions on Windows. With Visual C++ .NET, extensions have been added to support the .NET Framework. This means that existing C++ source code will continue to compile to native executable code without modification. It also means, however, that it will run independently of the .NET runtime. If you want your C++ code to run within the .NET Framework, you can simply add the following line to the beginning of your code:

#using

You can also pass the flag /clr to the compiler, which then assumes that you want to compile to managed code, and will hence emit IL instead of native machine code. The interesting thing about C++ is that when you compile to managed code, the compiler can emit IL that contains an embedded native executable. This means that you can mix managed types and unmanaged types in your C++ code. Thus the managed C++ code

class MyClass {

defines a plain C++ class, whereas the code

ref class MyClass {

gives you a managed class, just as if you had written the class in C# or Visual Basic 2010. The advantage of using managed C++ over C# code is that you can call unmanaged C++ classes from managed C++ code without having to resort to COM interop.

The compiler raises an error if you attempt to use features that are not supported by .NET on managed types (for example, templates or multiple inheritances of classes). You will also find that you need to use nonstandard C++ features when using managed classes.

Because of the freedom that C++ allows in terms of low-level pointer manipulation and so on, the C++ compiler is not able to generate code that will pass the CLR's memory type-safety tests. If it is important that your code be recognized by the CLR as memory type-safe, you will need to write your source code in some other language (such as C# or Visual Basic 2010).

COM and COM+

Technically speaking, COM and COM+ are not technologies targeted at .NET - components based on them cannot be compiled into IL (although it is possible to do so to some degree using managed C++, if the original COM component was written in C++). However, COM+ remains an important tool, because its features are not duplicated in .NET. Also, COM components will still work - and .NET incorporates COM interoperability features that make it possible for managed code to call up COM components and vice versa (this is discussed in Chapter 26, "Interop"). In general, however, you will probably find it more convenient for most purposes to code new components as .NET components, so that you can take advantage of the .NET base classes as well as the other benefits of running as managed code.

A CLOSER LOOK AT INTERMEDIATE LANGUAGE

From what you learned in the previous section, Microsoft Intermediate Language obviously plays a fundamental role in the .NET Framework. It makes sense now to take a closer look at the main features of IL, because any language that targets .NET will logically need to support these characteristics too.

Here are the important features of IL:

* Object orientation and the use of interfaces

* Strong distinction between value and reference types

* Strong data typing

* Error handling using exceptions

* Use of attributes

The following sections explore each of these features.

Support for Object Orientation and Interfaces

The language independence of .NET does have some practical limitations. IL is inevitably going to implement some particular programming methodology, which means that languages targeting it need to be compatible with that methodology. The particular route that Microsoft has chosen to follow for IL is that of classic object-oriented programming, with single implementation inheritance of classes.

If you are unfamiliar with the concepts of object orientation, refer to the Web Download Chapter 53, "C#, Visual Basic, C++/CLI, and F#" for more information.

In addition to classic object-oriented programming, IL also brings in the idea of interfaces, which saw their first implementation under Windows with COM. Interfaces built using .NET produce interfaces that are not the same as COM interfaces. They do not need to support any of the COM infrastructure (for example, they are not derived from IUnknown, and they do not have associated globally unique identifiers, more commonly know as GUIDs). However, they do share with COM interfaces the idea that they provide a contract, and classes that implement a given interface must provide implementations of the methods and properties specified by that interface.

You have now seen that working with .NET means compiling to IL, and that in turn means that you will need to use traditional object-oriented methodologies. However, that alone is not sufficient to give you language interoperability. After all, C++ and Java both use the same object-oriented paradigms, but they are still not regarded as interoperable. We need to look a little more closely at the concept of language interoperability.

So what exactly do we mean by language interoperability?

After all, COM allowed components written in different languages to work together in the sense of calling each other's methods. What was inadequate about that? COM, by virtue of being a binary standard, did allow components to instantiate other components and call methods or properties against them, without worrying about the language in which the respective components were written. To achieve this, however, each object had to be instantiated through the COM runtime, and accessed through an interface. Depending on the threading models of the relative components, there may have been large performance losses associated with marshaling data between apartments or running components or both on different threads. In the extreme case of components hosted as an executable rather than DLL files, separate processes would need to be created to run them. The emphasis was very much that components could talk to each other but only via the COM runtime. In no way with COM did components written in different languages directly communicate with each other, or instantiate instances of each other - it was always done with COM as an intermediary. Not only that, but the COM architecture did not permit implementation inheritance, which meant that it lost many of the advantages of object-oriented programming.

An associated problem was that, when debugging, you would still need to debug components written in different languages independently. It was not possible to step between languages in the debugger. Therefore, what we really mean by language interoperability is that classes written in one language should be able to talk directly to classes written in another language. In particular:

* A class written in one language can inherit from a class written in another language.

* The class can contain an instance of another class, no matter what the languages of the two classes are.

* An object can directly call methods against another object written in another language.

* Objects (or references to objects) can be passed around between methods.

* When calling methods between languages, you can step between the method calls in the debugger, even when this means stepping between source code written in different languages.

This is all quite an ambitious aim, but amazingly, .NET and IL have achieved it. In the case of stepping between methods in the debugger, this facility is really offered by the Visual Studio integrated development environment (IDE) rather than by the CLR itself.

(Continues...)



Excerpted from Professional C# 4.0 and .NET 4 by Christian Nagel Bill Evjen Jay Glynn Karli Watson Morgan Skinner Copyright © 2010 by John Wiley & Sons, Ltd. Excerpted by permission.
All rights reserved. No part of this excerpt may be reproduced or reprinted without permission in writing from the publisher.
Excerpts are provided by Dial-A-Book Inc. solely for the personal use of visitors to this web site.

Read More Show Less

Table of Contents

INTRODUCTION.

PART I: THE C# LANGUAGE.

CHAPTER 1: .NET Architecture.

CHAPTER 2: Core C#.

CHAPTER 3: Objects and Types.

CHAPTER 4: Inheritance.

CHAPTER 5: Generics.

CHAPTER 6: Arrays and Tuples.

CHAPTER 7: Operators and Casts.

CHAPTER 8: Delegates, Lambdas, and Events.

CHAPTER 9: Strings and Regular Expressions.

CHAPTER 10: Collections.

CHAPTER 11: Language Integrated Query.

CHAPTER 12: Dynamic Language Extensions.

CHAPTER 13: Memory Management and Pointers.

CHAPTER 14: Refl ection.

CHAPTER 15: Errors and Exceptions.

PART II: VISUAL STUDIO.

CHAPTER 16: Visual Studio 2010.

CHAPTER 17: Deployment.

PART III: FOUNDATION.

CHAPTER 18: Assemblies.

CHAPTER 19: Instrumentation.

CHAPTER 20: Threads, Tasks, and Synchronization.

CHAPTER 21: Security.

CHAPTER 22: Localization.

CHAPTER 23: System.Transactions.

CHAPTER 24: Networking.

CHAPTER 25: Windows Services.

CHAPTER 26: Interop.

CHAPTER 27: Core XAML.

CHAPTER 28: Managed Extensibility Framework.

CHAPTER 29: Manipulating Files and the Registry.

PART IV: DATA.

CHAPTER 30: Core ADO.NET.

CHAPTER 31: ADO.NET Entity Framework.

CHAPTER 32: Data Services.

CHAPTER 33: Manipulating XML.

CHAPTER 34: .NET Programming with SQL Server.

PART V: PRESENTATION.

CHAPTER 35: Core WPF.

CHAPTER 36: Business Applications with WPF.

CHAPTER 37: Creating Documents with WPF.

CHAPTER 38: Silverlight.

CHAPTER 39: Windows Forms.

CHAPTER 40: Core ASP.NET.

CHAPTER 41: ASP.NET Features.

CHAPTER 42: ASP.NET Dynamic Data and MVC.

PART VI: COMMUNICATION.

CHAPTER 43: Windows Communication Foundation.

CHAPTER 44: Windows Workfl ow Foundation 4.

CHAPTER 45: Peer-to-Peer Networking.

CHAPTER 46: Message Queuing.

CHAPTER 47: Syndication.

APPENDIX: Guidelines for Windows 7 and Windows Server 2008 R2.

INDEX.

ONLINE CHAPTERS.

CHAPTER 48: Graphics with GDI+.

CHAPTER 49: Visual Studio Tools for Office.

CHAPTER 50: Managed Add-In Framework.

CHAPTER 51: Enterprise Services.

CHAPTER 52: Directory Services.

CHAPTER 53: C#, Visual Basic, C++/CLI, and F#.

CHAPTER 54: .NET Remoting.

CHAPTER 55: Web Services with ASP.NET.

CHAPTER 56: LINQ to SQL.

CHAPTER 57: Windows Workfl ow Foundation 3.0.

Read More Show Less

Customer Reviews

Average Rating 3
( 8 )
Rating Distribution

5 Star

(1)

4 Star

(1)

3 Star

(4)

2 Star

(1)

1 Star

(1)

Your Rating:

Your Name: Create a Pen Name or

Barnes & Noble.com Review Rules

Our reader reviews allow you to share your comments on titles you liked, or didn't, with others. By submitting an online review, you are representing to Barnes & Noble.com that all information contained in your review is original and accurate in all respects, and that the submission of such content by you and the posting of such content by Barnes & Noble.com does not and will not violate the rights of any third party. Please follow the rules below to help ensure that your review can be posted.

Reviews by Our Customers Under the Age of 13

We highly value and respect everyone's opinion concerning the titles we offer. However, we cannot allow persons under the age of 13 to have accounts at BN.com or to post customer reviews. Please see our Terms of Use for more details.

What to exclude from your review:

Please do not write about reviews, commentary, or information posted on the product page. If you see any errors in the information on the product page, please send us an email.

Reviews should not contain any of the following:

  • - HTML tags, profanity, obscenities, vulgarities, or comments that defame anyone
  • - Time-sensitive information such as tour dates, signings, lectures, etc.
  • - Single-word reviews. Other people will read your review to discover why you liked or didn't like the title. Be descriptive.
  • - Comments focusing on the author or that may ruin the ending for others
  • - Phone numbers, addresses, URLs
  • - Pricing and availability information or alternative ordering information
  • - Advertisements or commercial solicitation

Reminder:

  • - By submitting a review, you grant to Barnes & Noble.com and its sublicensees the royalty-free, perpetual, irrevocable right and license to use the review in accordance with the Barnes & Noble.com Terms of Use.
  • - Barnes & Noble.com reserves the right not to post any review -- particularly those that do not follow the terms and conditions of these Rules. Barnes & Noble.com also reserves the right to remove any review at any time without notice.
  • - See Terms of Use for other conditions and disclaimers.
Search for Products You'd Like to Recommend

Recommend other products that relate to your review. Just search for them below and share!

Create a Pen Name

Your Pen Name is your unique identity on BN.com. It will appear on the reviews you write and other website activities. Your Pen Name cannot be edited, changed or deleted once submitted.

 
Your Pen Name can be any combination of alphanumeric characters (plus - and _), and must be at least two characters long.

Continue Anonymously
Sort by: Showing all of 8 Customer Reviews
  • Posted March 8, 2011

    a comprehensive book that covers EVERYTHING

    Professional C# 4 and .NET 4 takes readers on an extensive journey through all the useful capabilities this comprehensive language and framework have to offer. Thankfully, the book not only covers the language and the technology, but also the tools essential for effective software development. The book opens with a introduction to the C# language, walking through the .NET architecture, core elements of C#, inheritance, generics, delegates and LINQ. After a thorough introduction to the language, the book continues on to the practical aspect of development using Visual Studio 2010 and covers essential elements such as application deployment. The rest of the book focuses on advanced features of the C# language including assemblies, threading, localization and windows services. Part IV specifically focuses on Data, the Entity Framework and XML. Part V touches on presentation covering WPF, Silverlight, Windows Forms and MVC. The final chapters concentrate on communication and WCF. There are also several online chapters focusing on Visual Studio Tools, Enterprise Services, Directory Services and Web Services. There are many useful notes and tips interspersed throughout the book; a sure sign of years of experience. I found the book's extensive chapters on the C# language most useful for understanding what's new, what's old and what components could be most effective in the future. Overall, if you want a comprehensive reference on all things related to C# 4 and .NET 4, this a great place to start.

    Was this review helpful? Yes  No   Report this review
  • Anonymous

    Posted October 30, 2011

    No text was provided for this review.

  • Anonymous

    Posted October 25, 2011

    No text was provided for this review.

  • Anonymous

    Posted August 30, 2011

    No text was provided for this review.

  • Anonymous

    Posted March 29, 2011

    No text was provided for this review.

  • Anonymous

    Posted August 2, 2011

    No text was provided for this review.

  • Anonymous

    Posted July 27, 2011

    No text was provided for this review.

  • Anonymous

    Posted February 15, 2011

    No text was provided for this review.

Sort by: Showing all of 8 Customer Reviews

If you find inappropriate content, please report it to Barnes & Noble
Why is this product inappropriate?
Comments (optional)