Êíèãà: C# 2008 Programmer

Introduction

Introduction

Since the release of the Microsoft .NET Framework in July 2000, the C# programming language has gone through a few iterations to its latest version, 3.0. Over the years, the C# language has gained a lot of followers, partly due to its syntax, which is familiar to Java and C programmers. The clear syntax of the language made it easy to learn, and it's a popular choice for beginning programmers. In addition, the C# language is gaining a lot of traction in the Visual Basic camp, especially among VB6 programmers, who needed to move to .NET and did not want to learn a totally new variant of the Visual Basic language — Visual Basic .NET.

The latest version of C# 3.0 comes with .NET Framework 3.5. It contains many new features that makes the language more intuitive and powerful. Coupled with Visual Studio 2008, Microsoft's flagship development environment, developing applications using C# is now available to a wide audience.

In writing this book, I used the approach I believe is the easiest way to learn a new language — by examples. Often, books and articles get into too much of the theory without showing the readers what the concept looks like in code. For each topic, I try to provide numerous examples to illustrate the concept, and I would encourage you to make changes to the program to explore further. If you are an experienced programmer, you can jump directly to a particular chapter, as each chapter comes with independent examples.

Who This Book Is For

This book is for programmers of all levels. Beginning programmers should find the C# language easy to learn through the many code examples provided in each chapter. Experienced programmers can jump directly to individual chapters covering the topics of interest to them.

A conscious effort is made to illustrate each topic with independent code examples so that readers who want clarification on a topic do not need to wade through the entire chapter.

This book is ideal for the working programmer as well as students taking a semester course in C# programming. The sample projects covered in chapters 16 to 20 provide numerous project ideas as well as motivation for readers to get started working on bigger projects.

What This Book Covers

This book is divided into three parts. Part I covers the C# language fundamentals; Part II covers application development using C#, and Part III provides three appendices that cover the list of C# keywords, the .NET class libraries, and document generation using the Sandcastle utility.

Part I: C# Fundamentals

? Chapter 1 introduces the .NET Framework. It examines the key components in the .NET Framework as well as the role played by each of the components. In addition, it discusses the relationships between the various versions of the framework, from version 1.0 to the latest 3.5.

? Chapter 2 covers the use of Microsoft Visual Studio 2008 as the tool for C# development. Visual Studio 2008 is an extremely versatile and powerful environment for developing .NET applications. This chapter explores some of the common features that you will likely use in the process of your development work.

? Chapter 3 introduces the syntax of the C# language and covers all the important topics: C# keywords, variables, constants, comments, XML documentation, data types, flow control, loops, operators, and preprocessor directives.

? Chapter 4 tackles one of the most important topics in C# programming — classes and objects. Classes are essentially templates in from which you create objects. In C# .NET programming, everything you deal with involves classes and objects. This chapter provides a firm foundation in the use and creation of classes for code reuse.

? Chapter 5 explains how interfaces can be used to define the contract for a class. It also discusses difference between an interface and an abstract class.

? Chapter 6 looks at how inheritance facilitates code reuse, enabling you to extend the functionality of code that you have already written. This book explains the different types of inheritance and how to define overloaded methods and operators.

? Chapter 7 introduces the concept of delegates and events used in object oriented programming, and discusses what a delegate is and how delegates are used to implement events.

? Chapter 8 examines strings handling in C# and the various ways to manipulate them. For more complex strings pattern matching, you can use regular expressions. This chapter also covers the various ways to format your strings data.

? Chapter 9 looks into the basics of generics and how you can use them to enhance efficiency and type safety in your applications. Generics enable developers to define type-safe data structures without binding to specific fixed data types at design time.

? Chapter 10 explains how to write multithreaded applications using the Thread class in the .NET Framework. It also shows you how to create and synchronize threads as well as how to write thread-safe Windows applications.

? Chapter 11 delves into the concepts of files and streams in .NET. With streams, you can perform a wide range of tasks, including compressing and decompressing data, serializing and deserializing data, and encrypting and decrypting data. This chapter covers the various ways to manipulate files and the various stream objects in .NET.

? Chapter 12 deals with exception handling. An exception is a situation that occurs when your program encounters an error that it is not expecting during runtime. Understanding how to handle exceptions makes your program more robust and resilient.

? Chapter 13 examines arrays and collections. It discusses the many collection classes that you can use to represent groups of data in .NET.

? Chapter 14 introduces a new feature in .NET 3.5: Language Integrated Query (LINQ). It covers all the important implementations of LINQ — LINQ to Objects, LINQ to XML, LINQ to Dataset, and LINQ to SQL.

? Chapter 15 explores the concept of assemblies. In .NET, the basic unit deployable is called an assembly. Assemblies play an important part of the development process where understanding how they work is useful in helping you develop scalable and efficient .NET applications.

Part II: Application Development Using C#

? Chapter 16 demonstrates how you can build a Windows application using the C# language. The sample application illustrates how to perform FTP using the classes available in the .NET Framework. You will also see how to perform printing in a.NET application and how to deploy Windows applications using the ClickOnce technology.

? Chapter 17 takes you through building an ASP.NET web application in C#. You perform data binding using the new LinqDataSource control and see how to AJAX-enable your web pages.

? Chapter 18 illustrates Windows Mobile development using the .NET Compact Framework, a subset of the .NET Framework. It examines the basics of the Windows Mobile development and builds a sample RSS reader application. Finally, it shows you how to create a professional setup package for your application so that it can be distributed to your readers for installation.

? Chapter 19 helps you get started with Silverlight and provides an opportunity for you to get a feel for Silverlight development works. It covers Silverlight 1.0 and 2, and contains several examples showing the capabilities of Silverlight, including animation, media, and .NET integration.

? Chapter 20 provides a quick introduction to the new Windows Communication Foundation (WCF) technology and shows how it addresses some of the limitations of today's web services technology. While most books and conferences focus heavily on the theory behind WCF, this chapter shows you how to build WCF services and then explains the theory behind them. It ends with an example that creates a ticketing application, allowing multiple clients to obtain updated seat information in real time.

Part III: Appendixes

? Appendix A lists the various keywords in C# that are predefined and have special meanings to the compiler.

? Appendix B summarizes the features of the various versions of the .NET Framework and explains how to use the Object Browser feature in Visual Studio 2008 to browse the available namespaces and classes in the .NET Framework.

? Appendix C shows you how to generate MSDN-style documentation for your project using Visual Studio 2008 and a third-party documentation generation tool — Sandcastle.

What You Need to Use This Book

For all the examples demonstrated in this book, I used Microsoft Visual Studio Team System 2008. However, Microsoft has released a plethora of editions of Visual Studio designed for the different types of C# developers:

? Visual Web Developer 2008 Express Edition

? Visual C# 2008 Express Edition

? Visual Studio 2008 Standard Edition

? Visual Studio 2008 Professional Edition

? Visual Studio 2008 Team System 2008 Architecture Edition

? Visual Studio 2008 Team System 2008 Database Edition

? Visual Studio 2008 Team System 2008 Development Edition

? Visual Studio 2008 Team System 2008 Test Edition

? Visual Studio 2008 Team System 2008 Team Suite

For a detailed discussion of the features available in each edition, check out the following URL: http://msdn.microsoft.com/en-us/vs2008/products/cc149003.aspx.

Express editions are designed for hobbyists and are available for download at no charge. This is a great way to get started with Visual Studio 2008 and is ideal for students and beginning programmers. However, if you are a professional developer, you should purchase either the Standard or Professional Edition. If you are developing Windows Mobile applications, you need the Professional Edition (or higher). If you are working in a large development environment and need to develop collaboratively with other developers on large projects, check out the Team System editions.

If you are not ready to purchase Visual Studio 2008, you can always download a 90-day trial edition of Visual Studio 2008 Professional from http://msdn.microsoft.com/en-us/vs2008/products/cc268305.aspx.

Depending on the edition of Visual Studio you are using, some of the steps illustrated in this book may not appear exactly the same on your screen. However, the differences are minor, and you should not have any problem in following the steps outlines in each chapter.

In addition, readers using Windows Vista should launch Visual Studio 2008 (as well as the Command Prompt window) in Administrator mode. To do so:

? Click on Vista Start button.

? Locate the program you want to launch (Visual Studio 2008, or Command Prompt).

? Right-click on the program and select Run as Administrator.

Conventions

A number of conventions are used throughout the book to help you get the most from the text and keep track of what's happening.

Boxes like this one hold important, not-to-be forgotten information that is directly relevant to the surrounding text.

Tips, hints, tricks, and asides to the current discussion are offset and placed in italics like this.

As for styles in the text:

? New terms and important words are highlighted introduced.

? Keyboard strokes look like this: Ctrl+A.

? Filenames, URLs, and code within the text looks like this: persistence.properties.

? Code is presented in two different ways:

Code examples nearly always look like this.
Gray highlighting is used to show where new code is added to existing code, or to point out a specific section of code that's being explained in the text.

Source Code

As you work through the examples in this book, you may choose either to type in all the code manually or to use the source code files that accompany the book. All of the source code used in this book is available for download at www.wrox.com. Once at the site, simply locate the book's title (either by using the Search box or by using one of the title lists), and click the Download Code link on the book's detail page to obtain all the source code for the book.

Because many books have similar titles, you may find it easiest to search by ISBN; this book's ISBN is 978-0-470-28581-7.

Once you download the code, just decompress it with your favorite compression tool. Alternatively, you can go to the main Wrox code download page at www.wrox.com/dynamic/books/download.aspx to see the code available for this book and all other Wrox books.

Errata

Every effort is made to ensure that there are no errors in the text or in the code. However, no one is perfect, and mistakes do occur. If you find an error such as a spelling mistake or faulty piece of code in one of our books, we would be grateful for your feedback. By sending in errata, you may save another reader hours of frustration, and at the same time you will be helping us provide even higher-quality information.

To find the errata page for this book, go to www.wrox.com and locate the title using the Search box or one of the title lists. Then, on the book details page, click the Book Errata link. On this page, you can view all errata that has been submitted for this book and posted by Wrox editors. A complete book list including links to each book's errata is also available at www.wrox.com/misc-pages/booklist.shtml.

If you don't spot "your" error on the Book Errata page, go to www.wrox.com/contact/techsupport.shtml, and complete the form there to send us the error you have found. We'll check the information and, if appropriate, post a message to the book's errata page and fix the problem in subsequent editions of the book.

p2p.wrox.com

For author and peer discussion, join the P2P forums at p2p.wrox.com. The forums are a web-based system for you to post messages relating to Wrox books and related technologies and interact with other readers and technology users. The forums offer a subscription feature to email you topics of interest of your choosing when new posts are made to the forums. Wrox authors, editors, other industry experts, and your fellow readers are present on these forums.

At http://p2p.wrox.com, you will find a number of different forums that will help you not only as you read this book but also as you develop your own applications. To join the forums, just follow these steps:

1. Go to p2p.wrox.com, and click the Register link.

2. Read the terms of use, and click Agree.

3. Complete the required information to join as well as any optional information you wish to provide, and click Submit.

4. You will receive an email with information describing how to verify your account and complete the joining process.

You can read messages in the forums without joining P2P but to post your own messages, you must join.

Once you join, you can post new messages and respond to messages other users post. You can read messages at any time on the web. If you would like to have new messages from a particular forum emailed to you, click the Subscribe to this Forum icon by the forum name in the forum listing.

For more information about how to use the Wrox P2P, be sure to read the P2P FAQs for answers to questions about how the forum software works as well as many common questions specific to P2P and Wrox books. To read the FAQs, click the FAQ link on any P2P page.

Îãëàâëåíèå êíèãè


Ãåíåðàöèÿ: 0.035. Çàïðîñîâ Ê ÁÄ/Cache: 0 / 0
ïîäåëèòüñÿ
Ââåðõ Âíèç