Conventions Used in This Book
This book uses several conventions to help you prioritize and reference the information it contains.
In addition, the following special elements provide information beyond the basic instructions:
From concept to deployment, C#Builder Kick Start provides the information you need to begin building .NET applications with Borland C#Builder for Microsoft .NET.
I'm very interested in hearing your comments about
C#Builder Kick Start
. You are welcome to contact me at jmayo@MayoSoftware.com. I also
Part I: Overview of C#Builder and the C# Programming Language
Chapter 1. Introducing .NET and the C#Builder IDE
Borland is the first independent software vendor to license the .NET Framework from Microsoft. The benefit of this is that applications created with C#Builder are fully compatible with any other .NET application or library.
Because C#Builder is about building .NET applications quickly, it helps to understand why .NET is important, what it is, and how it works. The information in this section is not all-inclusive, but still very important. Understanding this basic information about .NET will enable you to answer many questions in the future.
In the past, languages, operating systems, and platforms were built for a different age, when the primary platform for applications was the desktop computer. When programs moved from the desktop to the Internet, existing tools needed additional APIs and other capabilities. Most often, these new capabilities were bolted onto the side of the language or tool to coerce them into working on the Internet. Although conventional tools have done remarkably well and brought the Internet to where it is today, there are still many challenges to
.NET was created to support the new age of Internet computing applications. Issues such as deployment, security, and versioning have become significant problems, which .NET addresses. A central part of .NET is the
Common Language Runtime (
, a virtual code execution engine that supports deployment, security, and versioning of code. With native compiled code, such capabilities are not possible. Because .NET
What Is .NET?
.NET is a platform for building distributed applications. It is
Windows Forms is a set of libraries for building graphical
ADO.NET is a set of object-oriented classes for building data
ASP.NET includes a Web Forms programming model, in which Web-based applications can be built and run over the Internet and accessed with a browser. This is an improved Web programming model in which code is actually compiled on the server but rendered to the client as traditional HTML. It is object-oriented and supports a server-based component model, promoting reusability.
Web Services are a new platform-independent and standards-based approach for enabling interoperability between heterogeneous systems on the Internet. .NET Web Services use the object-oriented infrastructure of the ASP.NET programming model, but still expose an open-standards message-based model. Using
These are just a few of the more popular application types that can be built with .NET. If you become familiar with the vast .NET Framework BCL, you will discover that it offers more capabilities to meet any need.
Base Class Library
The .NET Base Class Library (BCL) contains thousands of reusable types that increase productivity in building .NET applications. Because of BCL's size, it takes time to learn everything that is available. You can often save time by searching the BCL before duplicating a custom type that already exists.
As you start out, it is good to get a general overview of what is in the BCL and know where to look. Table 1.1 shows the major namespaces and descriptions of BCL types.
Table 1.1. .NET Namespaces
Common Language Runtime
The Common Language Runtime (CLR) is an execution engine with the primary purpose of providing managed execution of .NET code. The central point to remember about the CLR is the word "managed." The CLR
Managed code is not compiled to native machine code. Rather, it is compiled to Microsoft Intermediate Language (MSIL), which I'll refer to as just IL. Much like Java byte code (or just byte code), IL is an assembler-like language. However, one of the primary conceptual differences between byte code and IL is the fact that IL does not have an interpreted specification. IL is loaded and Just-In-Time (JIT) compiled to machine code in memory by the CLR at runtime. Another difference between Java byte code and IL is that IL is designed
.NET programs are composed of assemblies, which are the logical atomic unit of deployment, identification, and security. They
Another important feature to know about the CLR is how it loads and executes code. Understanding this process
Figure 1.1. CLR application management.
As soon as a .NET program begins execution, Windows detects that this is a .NET assembly and starts up the CLR. The CLR then identifies the program entry point and begins the Resolve Types process, in which it finds out where a given type is located. Identified assemblies are loaded by the Loader process.
This process illustrates why the .NET compiler is called a JIT compiler—types are loaded on an as-needed basis or just-in-time. The verification process ensures type safety and security. If the JIT compiler encounters a type that it needs, it will
The initial JIT compilation represents a noticeable performance hit, occurring when an application first starts. Subsequent performance of loads will vary, depending on the type retrieved. As hinted, these are only initial delays, and performance
After a type has been compiled to machine code, the memory manager handles it. Value types (structs) are allocated on the stack and reference types (classes) are allocated on the heap. Periodically, the garbage collector kicks in to clean up unused heap objects in a mark-and-sweep fashion. The garbage collector maintains generations, cleaning up
In-memory code is native machine code that has already been JIT compiled and can be fed directly to the CPU. The in-memory working set will
When the CPU needs to execute type
The CLR is central to all that happens in .NET. Understanding how it works is the key to writing well-behaved code that
Another important part of .NET is the concept of multilanguage support. IL is designed to support many languages. In fact, there are currently dozens of languages that target the CLR by compiling to IL. Besides C#, .NET ships with Visual Basic .NET, JScript .NET, J# .NET, and Managed C++. Other
The glue that holds all these languages together is referred to as the Common Type System (CTS). Although each language represents types in a unique manner, the underlying behavior and semantics of each type are the same to the CLR. The CTS defines which members a type may have: Field, Methods, Events, Properties, and Indexers. It also specifies their scope and visibility: public, internal, protected, protected internal, and private. Of course, this description is given through the perspective of C# keywords: Other languages may differ in keyword, but the underlying semantics of the CLR remain the same.
Why multiple languages? For a better perspective of the reasoning behind this approach, consider a large business with multiple software projects. It is often the case that the languages in many of these projects are different. Unless the developers are using a component technology such as COM, they are probably not getting much reuse of code between projects. Having multiple languages that target a single platform has more potential for reuse, which is an important business benefit.
The ability to code in multiple languages has benefits in business-to-business commerce also. The third-party component market is huge, with more companies joining the .NET arena every day. These companies can code their components in any .NET language they choose. These components are reusable by any other .NET application, regardless of the language it is being written in. Multiple language support in .NET opens new markets to component vendors that, in the past, might have been difficult to support and reach.
The Common Language Specification (CLS) was created to address these problems. The CLS is
C#Builder is an