Part I AL The C# Language Chapter 1: Introducing C# D Chapter 5: More About Variables TE Chapter 4: Flow Control MA Chapter 3: Variables and Expressions RI Chapter 2: Writing a C# Program TE Chapter 6: Functions GH Chapter 7: Debugging and Error Handling Chapter 8: Introduction to Object-Oriented Programming RI Chapter 9: Defining Classes PY Chapter 10: Defining Class Members CO Chapter 11: Collections, Comparisons, and Conversions Chapter 12: Generics Chapter 13: Additional OOP Techniqu
1 Introducing C# Welcome to the first chapter of the first section of this book. This section will provide you with the basic knowledge you need to get up and running with C#. This chapter provides an overview of C# and the .NET Framework, including what these technologies are, the motivation for using them, and how they relate to each other. First is a general discussion of the .NET Framework. This technology contains many concepts that are tricky to come to grips with initially.
Part I: The C# Language In addition, the preceding definition of the .NET Framework includes no restriction on the type of applications that are possible. That’s because there is no restriction — the .NET Framework allows the creation of Windows applications, Web applications, Web services, and pretty much anything else you can think of. The .
Chapter 1: Introducing C# For C# code to execute, it must be converted into a language that the target operating system understands, known as native code. This conversion is called compiling code, an act that is performed by a compiler. Under the .NET Framework, however, this is a two-stage process. MSIL and JIT When you compile code that uses the .NET Framework library, you don’t immediately create operating system–specific native code.
Part I: The C# Language Managed Code The role of the CLR doesn’t end once you have compiled your code to MSIL, and a JIT compiler has compiled that to native code. Code written using the .NET Framework is managed when it is executed (a stage usually referred to as runtime). This means that the CLR looks after your applications by managing memory, handling security, allowing cross-language debugging, and so on.
Chapter 1: Introducing C# 2. That code is compiled into MSIL, which is stored in an assembly (see Figure 1-2). C#application code Compilation Assembly Figure 1-2 3. When this code is executed (either in its own right if it is an executable or when it is used from other code), it must first be compiled into native code using a JIT compiler (see Figure 1-3). Assembly JIT Compilation Native Code Figure 1-3 4.
Part I: The C# Language practically forgotten about when completed. This also makes it easy to locate specific pieces of code when you need them and enables teams of developers to divide up the programming burden into manageable chunks, whereby individuals can “check out” pieces of code to work on without risking damage to otherwise satisfactory sections or sections other people are working on.
Chapter 1: Introducing C# ❑ Web applications: These are Web pages such as might be viewed through any Web browser. The .NET Framework includes a powerful system for generating Web content dynamically, allowing personalization, security, and much more. This system is called ASP.NET (Active Server Pages .NET), and you can use C# to create ASP.NET applications using Web Forms. ❑ Web services: These are a new and exciting way to create versatile distributed applications.
Part I: The C# Language ❑ VS includes designers for Windows Forms and Web Forms applications, enabling simple drag-and-drop design of UI elements. ❑ Many types of C# projects may be created with “boilerplate” code already in place. Instead of starting from scratch, you will often find that various code files are started for you, reducing the amount of time spent getting started on a project.
Chapter 1: Introducing C# This is very useful because it enables you to work on shared code (which might be placed in the GAC) at the same time as applications that use this code. Debugging code is a lot easier when only one development environment is used, because you can step through instructions in multiple code modules. Summar y In this chapter, you looked at the .NET Framework in general terms and discovered how it makes it easy for you to create powerful and versatile applications.