Author: Simon Robinson et al. (USA)
Publisher:
Publish Date: 2005-06-01
Features: C# and .NET provide a brand-new development environment for programming on the Windows platform, where almost all Windows and Web applications can be developed. This book comprehensively introduces C# programming knowledge while providing the necessary background to understand the working principles of the .NET architecture. Compared to the previous two versions, it has added content on application deployment and localization. This book is a C# reference for developers and a valuable resource for C# and .NET users. Through learning this book, you will gain an in-depth understanding of various aspects of the C# language and be able to apply C# in the .NET environment, build Windows forms, access databases with ADO.NET, write components with ASP.NET, and leverage .NET to support COM and COM+.
Main Content:
· Object-oriented programming with C#
· Handling XML with C#
· Integrating COM, COM+, and Active Directory
· Writing Windows applications and Windows services
· Developing distributed applications with .NET Remoting
· Understanding .NET assemblies
· Creating graphics with C#
· Controlling .NET security
Target Audience: This book is suitable for developers with experience in C++, Visual Basic, or J++ programming, as well as for beginner programmers who wish to delve deeper into C#. For developers, it is not an exaggeration to describe C# and its related environment, the .NET Framework, as one of the most important technologies in recent years. The .NET Framework provides a new environment where almost all applications running on Windows can be developed, and C# is a new programming language specifically designed for .NET. For example, with C#, you can write dynamic web pages, XML web services, components for distributed applications, database access components, or traditional Windows desktop applications. This book introduces the .NET Framework 1.1, the second version of the .NET Framework, but most of its content is also applicable to the .NET Framework 1.0. If you are coding with version 1.0, some modifications will be required, and this book will point out the necessary changes. Do not be misled by the name .NET; it only emphasizes Microsoft's belief that distributed applications are the future trend, where processes are distributed between clients and servers. However, C# is not just a language for writing Internet or network-related applications; it also provides a way to write almost any type of software or component for the Windows platform. Additionally, both C# and .NET have revolutionized the way programs are written, making it easier to program on Windows. This is a significant statement. After all, as we all know, the development of computer technology is very fast, and Microsoft releases new software, programming tools, or new versions of Windows every year, claiming they are very useful for developers, and .NET and C# are no exception.
The Importance of .NET and C#
To understand the importance of .NET, it may help to consider the nature of many Windows technologies that have emerged in the past decade. Although all Windows operating systems appear completely different on the surface, from Windows 3.1 (1992) to Windows Server 2003, they all share the same Windows API at their core. When we switch to a new version of Windows, the API is enriched with many new features, but this is a process of evolution and expansion, not replacement. Many of the technologies and architectures used to develop Windows software are similar. For example, COM (Component Object Model) was developed as part of OLE (Object Linking and Embedding), and at that time, it was largely used to link different types of office documents together, so it could place a small Excel spreadsheet in a Word document. Over time, it evolved into COM, DCOM (Distributed Component Object Model), and finally COM+. COM+ is a complex technology that is the foundation for almost all component communication methods, implementing transaction processing, message queuing services, and object pooling. Microsoft's choice of this path is very clear: it prioritizes backward compatibility. Over the years, third-party vendors have written a significant amount of Windows software. If Microsoft introduced a new technology that did not follow the existing codebase every time, Windows would not have achieved the success it has today. Backward compatibility is a crucial feature of Windows technology and a long-standing strength of the Windows platform, but it has a major drawback. Every time a technology evolves and adds new features, it becomes more complex. Clearly, improvements are necessary. Microsoft cannot continue to expand these development tools and languages indefinitely, keeping up with the latest hardware developments while maintaining backward compatibility with Windows products that became popular in the early 1990s. To get a simpler and more specialized language, environment, and development tools that allow developers to write excellent software more easily, a new starting point is needed. This is where C# and .NET come into play.
Roughly speaking, .NET is a new programming architecture for Windows—a new API. C# is a new language that can leverage all the new features of the .NET Framework and its development environment, as well as the object-oriented programming methods that have emerged in the past 20 years. Before proceeding, it must be clarified that backward compatibility has not been lost in this evolutionary process. Existing programs can still be used, and .NET is also compatible with existing software. Communication between software components on Windows is now almost always done using COM. Therefore, .NET can provide wrappers for existing COM components to allow .NET components to communicate with them. Microsoft has extended C++ to provide a new language, J#, and has made many improvements to VB, transforming it into the more powerful VB.NET, allowing code written in these languages to be used in the .NET environment. However, these languages cannot fully leverage current technologies due to their evolutionary history. This book will introduce C# programming techniques while providing the necessary background on how the .NET architecture works. We will not only cover the basics of the C# language but also provide application examples using various related technologies, including database access, dynamic web pages, advanced graphics techniques, and directory access. The only requirement is that users be familiar with at least one high-level language for Windows, such as C++, VB, or J++.
Advantages of .NET
The advantages of .NET have been discussed, but it has not been said to make the work of developers easier. In this section, we will briefly discuss the improved features of .NET.
● Object-oriented programming: The .NET Framework and C# are completely object-oriented from the beginning.
● Excellent design: A base class library designed in a very intuitive way.
● Language independence: In .NET, languages such as VB.NET, C#, J#, and Managed C++ can all be compiled into a common Intermediate Language (IL). This means that languages can interact in ways they could not before.
● Support for dynamic web pages: ASP is very flexible but not very efficient, as it uses an interpreted scripting language and lacks object-oriented design, resulting in messy ASP code. .NET uses a new technology, ASP.NET, which provides integrated support for web pages. With ASP.NET, the code in pages can be compiled, and this code can be written in .NET advanced languages such as C#, J#, or VB.NET.
● Efficient data access: A set of .NET components collectively known as ADO.NET provides efficient access to relational databases and various data sources. These components can also access file systems and directories. .NET has built-in XML support and can handle data imported or exported from non-Windows platforms.
● Code sharing: .NET introduces the concept of assemblies to replace traditional DLLs, providing a flawless way to share code between applications. Assemblies have a formal system to resolve version conflicts, and different versions of assemblies can coexist.
● Enhanced security: Each assembly can also contain built-in security information, which can accurately specify who or what type of user or process can call which methods of which classes. This allows for very precise control over how assemblies are used.
● No impact on installation: There are two types of assemblies: shared assemblies and private assemblies. Shared assemblies are public libraries that can be used by all software, while private assemblies are used only by a specific application. Private assemblies are fully functional, so the installation process is very simple, with no registry entries required—just place the corresponding files in the appropriate folders of the file system.
● Support for web services: .NET provides complete support for developing web services, allowing users to develop any type of application.
● Visual Studio .NET 2003: .NET comes with a development environment, Visual Studio .NET, which can be used to write code in C++, C#, J#, VB.NET, and ASP.NET. Visual Studio .NET integrates all the best features of the language-specific environments in Visual Studio 6.
● C#: A new object-oriented language for .NET. Chapter 1 will discuss the advantages of the .NET architecture in detail.
New Features in the .NET Framework 1.1
The first version of the .NET Framework (1.0) was released in 2002 and was widely praised. The new version of the .NET Framework, 1.1, was released in 2003 and is considered a minor improvement to the architecture. Even with smaller improvements, the new version still has some significant changes and additions worth exploring. In all the improvements made to the .NET Framework 1.1 version, Microsoft has tried to ensure that the changes to code written with the 1.0 version are as minimal as possible. Despite this effort, there are still some notable changes in the new version. Many code improvements were made to enhance security. Readers can find the complete list of improvements on Microsoft's GotDotNet web site (http://www.gotdotnet.com). Below, we will discuss some of the improvements in the 1.1 version of the .NET Framework and the new features in Visual Studio .NET 2003 (.NET Framework 1.1 development environment).
Portability
When using the .NET Framework 1.0 and Visual Studio .NET 2002, to create portable applications, you had to download the Microsoft Mobile Internet Toolkit (MMIT). However, with the .NET Framework 1.1 and Visual Studio .NET 2003, you can directly create portable applications without downloading any additional toolkits. This is evident when creating new projects in Visual Studio .NET 2003. For example, when viewing the list of C# project types that can be created, you will see ASP.NET Mobile Web Application and Smart Device Application. The ASP.NET Mobile Web Application project type can be used to create web-based mobile applications. The Smart Device Application project type can create applications for Pocket PC or other Windows CE devices. Third-party client applications for Windows CE devices use the Compact Framework, which is a trimmed-down version of the .NET Framework. When you open any type of portable project, a set of portable server controls will be listed in the Visual Studio .NET toolbox, and you can use these controls to create applications.
New Data Providers
Another major change in the new architecture is ADO.NET. ADO.NET is the .NET way of accessing and processing data, and now it has two new data providers: one for ODBC and another for Oracle. With the .NET Framework 1.0, you could use the ODBC data provider, but it had to be downloaded separately. Additionally, once downloaded, the namespace for this data provider was Microsoft.Data.Odbc. In the .NET Framework 1.1, the ODBC data provider is built-in and does not require separate download. Moreover, you can use ODBC data sources, access ODBC data connections, data adapters, and data reader objects through the System.Data.Odbc namespace. The other new data provider is for handling Oracle databases. Oracle databases are widely used in enterprises, and the lack of an Oracle data provider is often a major obstacle for .NET to enter the enterprise market. To use this new data provider, you need to reference the System.Data.OracleClient namespace in your project.
New Language: Visual J#
When installing Visual Studio .NET 2003, note that this version provides a new language, Visual J#, for building .NET applications. Before this version, Visual Studio .NET 2002 required the separate installation of this language. Visual J# is often referred to as J# (pronounced J-Sharp), the new version of Visual J++ and is very similar to the Java language, making it easy for Java developers to migrate to .NET. J# developers will use the .NET class library instead of the Java runtime library. On the .NET platform, J# developers will have the same capabilities as C# developers. With J#, you can also create .NET classes, Windows Forms applications, ASP.NET web applications, and XML web services. Additionally, like other .NET-compatible languages, you can use J# in a cross-language manner. For example, you can create a J# class and use it in a C# application, or you can create a C# class and use it in a J# application. Like other languages, there is a built-in compiler for J# in the .NET Framework. All compilers are located in the directory C:\Windows\Microsoft.NET\Framework\v1.1.xxxx. The C# compiler is csc.exe, the VB.NET compiler is vbc.exe, and the J# compiler is vjc.exe.
Side-by-Side Execution
Side-by-side execution refers to running multiple versions of applications on the same server, where different application versions use different runtime library versions. Microsoft has always promised to provide this feature to developers, but it has always been difficult to visualize because you can only use one version of the Framework. After the release of the second version of the Framework, .NET Framework 1.1, you can now see this feature provided by Microsoft. Now, you can create .NET applications for the new version of the .NET Framework 1.1 while still allowing old applications targeting the .NET Framework 1.0 to continue running as before.
Support for Internet Protocol 6 (IPv6)
Recently, much of the Internet runs on IPv4, also known as IPv4. It provides IP addresses, such as 255.255.255.255. The .NET Framework 1.1 now supports IPv6, which was created in 1995 and solved many of the problems faced by IPv4. If people had continued to use IPv4, the available IP addresses would have been exhausted very quickly. The .NET Framework 1.1 supports IPv6 through the System.Net namespace, and ASP.NET and XML web services also support IPv6.
Improvements in Visual Studio .NET 2003
When upgrading the .NET Framework, Visual Studio .NET itself was also upgraded. Note that there are new graphics on the start page, and the organization of objects on the page has also changed. Additionally, a major change in the new IDE is that once installed, it is not just an upgrade from Visual Studio .NET 2002 to Visual Studio .NET 2003, but rather a completely new version of the IDE. If Visual Studio .NET 2002 is already installed on your machine, you will get two completely independent VS.NET IDEs. So, if you want to create and use applications targeting the .NET Framework 1.0, use VS.NET 2002; if you want to create and use applications targeting the .NET Framework 1.1, use VS.NET 2003. Also, note that when you open a project created with VS.NET 2002, the system will ask if you want to upgrade the project to a VS.NET 2003 project. If you answer "yes," the project will be upgraded to an application targeting the .NET Framework 1.1. Note that this is an irreversible process.
In addition to these major changes, the IDE in VS.NET 2003 has a higher level of intelligence in Intellisense and stronger code completion capabilities. This book will use this version of the IDE.
Advantages of C#
C# can be seen as a .NET-oriented programming language for the Windows environment. Over the past decade, Microsoft has added many features to Windows and the Windows API, and both VB and C++ have undergone many changes. Although VB and C++ have ultimately become very powerful languages, they also have problems because they retain some of their original characteristics. For Visual Basic, its main advantage is that it is very easy to understand, and many programming tasks are very easy to accomplish, basically hiding the of the Windows API and COM component structure. Its disadvantage is that Visual Basic never truly achieved object-oriented programming, so it is difficult to decompose and maintain large applications. Additionally, because the syntax of VB inherits from early versions of BASIC (BASIC was mainly designed for beginners rather than for writing large commercial applications), it cannot truly be a structured or object-oriented programming language. On the other hand, C++ has its own roots in the ANSI C++ language definition. It is not completely compatible with ANSI because Microsoft wrote the C++ compiler before the ANSI definition was standardized, but it is very close. Unfortunately, this led to two problems. First, ANSI C++ was developed under the technological conditions of the past decade, so it does not support modern concepts (such as Unicode strings and generating XML documents), and some outdated syntax structures were designed for older compilers (such as separating the declaration and definition of member functions). Second, Microsoft also tried to evolve C++ into a language for performing high-performance tasks on Windows, avoiding the addition of a large number of Microsoft-specific keywords and libraries. The result is that in Windows, the language has become very messy. Let a C++ developer say how many ways there are to define a string, and you can see this point: char\, LPTSTR, string, CString (MFC version), CString (WTL version), wchar\_t\, and OLECHAR\ are just a few examples.
Now, enter the .NET era—a completely new environment that has extended both of these languages. Microsoft has added many Microsoft-specific keywords to C++, and it has evolved VB into VB.NET, retaining some basic VB syntax but with a completely different design, making VB.NET a new language from a practical application perspective. Here, Microsoft has decided to give developers another choice—a new language specifically for .NET with a new starting point, namely Visual C#.NET. Microsoft describes C# as a simple, modern, object-oriented, type-safe programming language derived from C and C++. Most independent commentators describe it as "derived from C, C++, and Java." This description is technically accurate but does not involve the real advantages of the language. From a syntax perspective, C# is very similar to C++ and Java, with many of the same keywords, and C# also uses a block structure similar to C++ and Java, marking code blocks with parentheses ({}) and separating statements with semicolons. The impression one gets of C# code is that it is very similar to C++ or Java code. But behind these surface similarities, C# is much easier to learn than C++ but slightly more difficult than Java. Its design is more adaptable to modern development tools and has the ease of use of Visual Basic, high performance, and the low-level memory access of C++. C# includes the following features:
● Fully supports classes and object-oriented programming, including interfaces and inheritance, virtual functions, and operator overloading.
● Defines a complete and consistent set of basic types.
● Built-in support for automatically generating XML documentation comments.
● Automatic cleanup of dynamically allocated memory.
● Allows marking classes or methods with user-defined attributes, which can be used for documentation purposes and has an impact on compilation (e.g., marking a method as compiled only in debug mode).
● Full access to the .NET base class library and easy access to the Windows API.
● Allows the use of pointers and direct memory access, but C# can access memory without them.
● Supports properties and events in the style of VB.
● Allows changing compiler options to compile the program into an executable file or a .NET component library, which can be called by other code in the same way as ActiveX controls (COM components).
● C# can be used to write ASP.NET dynamic web pages and XML web services.
It should be noted that for most of the above features, VB.NET and Managed C++ also have them. But C# has been using .NET from the beginning, with complete support for .NET features and providing a more suitable syntax than other languages. C# itself is very similar to Java, but there are some improvements because Java was not designed for use in the .NET environment.
Before concluding this topic, it is also worth noting two limitations of C#. One is that the language is not suitable for writing time-critical or very high-performance code, such as a loop that runs 1000 or 1050 times and immediately cleans up the resources it occupies when it is not needed. In this regard, C++ may still be the best among all low-level languages. The other is that C# lacks key features needed for very high-performance applications, including inline functions that are guaranteed to run at specific points in the code and destructors. But such applications are very rare.
Environment Needed to Write and Run C# Code
.NET runs on Windows 98, 2000, XP, and 2003. To write code with .NET, you need to install the .NET SDK unless you are using Windows Server 2003, which has the .NET Framework 1.0 and 1.1 built-in. Unless you are writing C# code with a text editor or other third-party development environment, you generally use Visual Studio .NET 2003. Running managed code does not require installing the full SDK, but you do need the .NET runtime, which needs to be distributed to client machines that do not have it installed.
Content of This Book
In this book, the first chapter introduces the overall structure of .NET and provides the background knowledge needed to write managed code. After that, the book is divided into several parts to introduce the C# language and its applications in various fields.
Part I (Chapters 1~11) — C# Language
This part provides background knowledge for the C# language. It does not specify any language but assumes the reader is an experienced programmer. It begins with the basic syntax and data types of C#, then covers the object-oriented features of C#, followed by some advanced topics in C#.
Part II (Chapters 12~18) — .NET Environment
This part introduces the rules for programming in the .NET environment. It focuses on Visual Studio .NET, security, thread deployment for .NET applications, and how to create libraries as assemblies.
Part III (Chapters 19~20) — Windows Forms
This part discusses the creation of traditional Windows applications, which are called Windows Forms in .NET. Windows Forms are the client versions of applications, and using .NET to create these types of applications is a quick and simple way to achieve this task. In addition to introducing Windows Forms, we will also discuss GDI+, a technology that can be used to create applications containing advanced graphics.
Part IV (Chapters 21~24) — Data
This part introduces how to use ADO.NET to access databases and interact with directories and Active Directory. We also explain in detail the .NET support for XML and its support for the Windows operating system.
Part V (Chapters 25~27) — Web Programming
This part introduces how to write components that run on websites and how to write web pages. This includes the use of ASP.NET and the development of web service programs.
Part VI (Chapters 28~29) — Interoperability
COM's backward compatibility is an important part of .NET, and COM+ is responsible for transaction processing, object pooling, and message queuing. This part introduces .NET's support for handling COM and COM+ and discusses how to write C# code that interacts with these technologies.
Part VII (Chapters 30~32) — Windows Basic Services
This part is a summary of the main content of the book, introducing how to access files and the registry, how to access the Internet through applications, and how to use Windows services.
Part VIII — Appendices
This part contains several appendices that provide detailed information on object-oriented programming rules and information specific to the C# programming language. These appendices are not provided in the book but are available as PDF versions on the web site mentioned in the book: http://www.wrox.com.
How to Download the Sample Code in This Book
When learning the examples in this book, you can choose to manually enter all the code or use the source code files related to the book. All the source code in this book can be downloaded from http://www.wrox.com/. When you log in to this site, you can use the Search tool or the book title list to find this book. Then, click the Download Code link on the book information page to obtain all the source code.
Tip: Many book titles are very similar, so it is simpler to find this book by its ISBN, which is 0-7645-5759-9. After downloading the code, you can use your favorite compression tool to decompress it. Additionally, you can also go to the main download page for Wrox code at http://www.wrox.com/dynamic/books/download.aspx to see the code used in this book and other Wrox books.
Errata
Although we have made every effort to ensure the accuracy of this book, errors are inevitable. If you find any errors in the book, such as spelling errors or code errors, please let us know—we will be very grateful. The errata list allows other readers to avoid frustration, and it also helps provide higher-quality information. To find the errata list for this book on the web site, log in to http://www.wrox.com, use the Search tool or the book title list to find this book, and then click the Book Errata link on the book information page. On this page, you can see all the errata that has been submitted and reviewed by the editor. The complete list of book errata links is available through http://www.wrox.com/misc-pages/booklist.shtml. If you do not find the error you discovered on the Book Errata page, you can enter http://www.wrox.com/contact/techsupport.shtml and fill out the form to send the error to us. We will review your information and, if it is correct, upload it to the book's errata page or adopt it in the book's subsequent version.
p2p.wrox.com
The P2P mailing list was established for discussions between the author and readers. Readers can join the P2P forum on p2p.wrox.com. The forum is a web-based system for transmitting information related to Wrox books and related technologies, as well as for interacting with other readers and technology users. The forum provides subscription functionality, where you will receive messages on the topics you choose when new posts are made on the forum. Wrox authors, editors, and other industry experts and readers will discuss on this forum. There are many different forums on http://p2p.wrox.com that help readers read this book and also benefit when developing their own applications. To join the forum, follow these steps:
(1) Enter p2p.wrox.com and click the Register link.
(2) Read the content and click the Agree button.
(3) Provide the information needed to join the forum and optional information you are willing to provide, then click the Submit button. You will then receive an email with instructions on how to verify your account and complete the joining process.
Tip: You can read the information on the forum without joining P2P, but only by joining the forum can you send your own messages. After joining the forum, you can send new messages and respond to other users' posts. You can read the information on the web at any time. If you want the forum to send you new messages, you can click the SubscribetothisForum icon for that forum in the forum list. For more information on using Wrox P2P, you can read the P2P FAQ to understand how the forum software works and many common questions and answers related to P2P and Wrox books. To read the FAQ,click the FAQ link on any P2P page.
Advanced C# Programming (3rd Edition)
📌 Related Posts
News
What is the reason for the newborn's yellow complexion when the jaundice value is not high?
2026-09-19
Literature
Selected Works of Bing Xin
2026-09-20
Literature
Grammar and Vocabulary. Cloze Test - English Major TEM-4 High Score Pass
2026-10-05
News
Do you have questions about the prostate?
2026-10-09
Literature
Feiyun Jinglan 1. Tengyun Juan
2026-10-17
Literature
A Brief History of Ancient Chinese Music (Revised Edition)
2026-10-17
Literature
Otherworldly realm, Love's flower blooms
2026-10-17
Literature
Goodbye,:SelectedRomanticPoemsbyXuZhimo
2026-10-17