Team LiB
Previous Section Next Section

Chapter 2. Introduction to C#

IN BRIEF

In this chapter, you will be introduced to various aspects of the .NET Framework, including data types, the Common Language Runtime, and garbage collection. The goal of this chapter is to give you a basic understanding of the .NET Framework, how it works, and how C# is an integral part of that framework. You don't have to have any previous exposure to C# to read this book. Some background and experience with programming in general would be helpful, but is also not necessary.

WHAT YOU NEED

RECOMMENDED SOFTWARE

.NET Framework Visual Studio .NET

RECOMMENDED HARDWARE

.NET-enabled desktop client

SKILLS REQUIRED

Basic programming skills


INTRODUCTION TO C# AT A GLANCE

Why Learn Yet Another Language?

37

  

Learning Common Types

38

  
 

Understanding Value Types

38

Reference Versus Value Types

40

 

Understanding Reference Types

39

  

What Is the Common Language Runtime?

40

  
 

Multiple Languages, One Runtime

42

The JIT Compiler

43

 

Isolation

42

Code Execution

43

 

Platform Invoke

42

COM Interoperability

43

 

Code Access Security

42

Rotor: Microsoft's Shared Source Common Language Infrastructure

44

Take Out the Trash: Theory of Garbage Collection

44

  
 

Reference Counting

44

Partial Collection

45

 

Generations

44

Nondeterministic Finalization

45

 

Collection

45

Using IDisposable to Create Well-Behaved Objects

46

Introduction to the Base Class Library

48

  

The Canonical "Hello World" Example

49

  


Welcome to the .NET Framework. One of the main goals of the .NET Framework is to provide a universal, safe type system through which any language can communicate with managed code written in any other language. By defining a common set of data types, such as int, char, string, and the like, it also provides the ability for an object written in one language to be used and accessed in another language. As a result of the .NET Framework effort, C# was developed to harness the power of the platform. In addition, C# represents an evolution in language design.

C# features many object-oriented features, such as properties for data encapsulation, polymorphic behavior, inheritance, and interface implementation. In addition, C# allows for a developer to tap into unsafe code (discussed later) when performance is at a premium. C# was developed to provide the best aspects of C++, Java, SmallTalk, and Modula2. Elements from each of the languages can be seen in C# and in the Common Language Runtime itself.

    Team LiB
    Previous Section Next Section