Skip to main content
main-content

Über dieses Buch

Expert C# 5.0 is a book about getting the best from C#. It’s based on the principle that to write good, high-performance, robust applications you need to understand whats going on deep under the hood. If you are already experienced with writing managed applications and want to learn more about how to get the best from the language at an advanced level, then this is the book for you.

Expert C# 5.0 discusses the familiar C# language in forensic detail. Examining familiar elements closely to reveal how they really work. Key language features that you are already familiar with, such as Enums, Strings and Collections, are teased apart and examined under the twin microscopes of MSIL (Intermediate Language) and the Windbg debugger to see what's really going on behind the scenes as your code is compiled and passed to the CLR.

This unparalleled depth of explanation will help you to become a true master of the C# language and architect better crafted applications that work in the most efficient and reliable way possible. It will also give you the insight you need to rapidly identify and fix the stubborn coding faults that others may be unable to diagnose.

Inhaltsverzeichnis

Frontmatter

Chapter 1. Reintroducing C#:-A Detailed Look at the Language We All Know

Abstract
This chapter will discuss the basics of the C# language. It begins with an example of a square number generator program to explain the basic structure of a C# program, how the C# compiles a C# program, and then explains Just-in-Time compilation. You will learn about the lexical element of the C# language, different types such as value and reference types, variables, parameters, and statements, and about the interface, enum, and delegate classes.
Mohammad Rahman

Chapter 2. C# Objects in Memory

Abstract
This chapter examines the C# object and the relation between it and the stack and heap of the memory. The life of the value type stays in the stack, whereas the reference type stays in the heap. I will explain about these using the windbg.exe program and discuss the different sections of the memory while the CLR executes any .NET application.
Mohammad Rahman

Chapter 3. Parameters

Abstract
This chapter will discuss the parameters in C#. The focus will be to show different ways of passing parameters to a method, such as pass by value, pass by reference, and pass default value of the parameter. You will find explanations of these in detail and see how CLR handles these behind the scene.
Mohammad Rahman

Chapter 4. Methods

Abstract
This chapter will discuss the following C# methods: instance, static, anonymous, and extension. In doing so, you’ll learn how the this keyword relates to these methods and how the CLR passes value for the this keyword used as parameter in runtime by examining data on the stack.
Mohammad Rahman

Chapter 5. Automatic Property Declaration

Abstract
This chapter will discuss automatic property declaration, which is a simplified syntax to declare a property for a class. I will also discuss the implicit variable declaration using the var keyword and show how var is handled by the C# compiler in design and runtime. Finally, I will discuss the anonymous type declaration and how the C# compiler compiles it.
Mohammad Rahman

Chapter 6. Enum

Abstract
This chapter will discuss one of the nice features of the C# language: enumerated type or enum for short. I will show you how the enum type is defined in the .NET Framework, how you can get symbolic names and values from the enum, and how enum parses in C#.
Mohammad Rahman

Chapter 7. Delegate

Abstract
This chapter will discuss delegates. First, we will examine the C# delegate compared to the function pointer in C language, which will give you a basic idea of the similarity between the function pointer in C and delegate in .NET. This will also build a background knowledge about the function pointer, which will help you understand the internal working of delegates. Finally, you will explore generic delegates such as Func and Action in .NET by examining how the C# compiler takes care of the Func and Action delegates.
Mohammad Rahman

Chapter 8. Event

Abstract
This chapter will discuss the event program. A type that defines an event member allows other types to subscribe for the notification when something happened in the type. We start by designing a type, which, when exposed to the event where subscribers are to subscribe, implements the code to handle the event and explains the concept of the event in C# language. We will then explore the behind the scenes workings of the event, for example, how C# compiler translates an event member to implement, add, and remove a method. We also examine how the subscription operator, for example, += and -=, will be translated to use the add and remove method compiled for the event member by the C# compiler. Finally, we will also explore how different pieces of the event program fit together in runtime.
Mohammad Rahman

Chapter 9. Foreach and Iterator

Abstract
This chapter will discuss the foreach statement and iterators block. The foreach statement is used to iterate an array or an object collection that implements the System.Collections.IEnumerable or System. Collections.Generic.IEnumerable<T> interface. The iterators block is also used to iterate through an array or an object collection based on the state machine generated automatically by the C# compiler.
Mohammad Rahman

Chapter 10. The String Data Type

Abstract
This chapter will discuss the string data type in Microsoft .NET Framework using C# language. First I will show how the CLR manages to instantiate a string in .NET. I will then discuss string immutability through which CLR ensures that when a string is created, it can’t be changed, and examine its contents, chaining operations in string, and various concatenation techniques used in .NET Framework for the string.
Mohammad Rahman

Chapter 11. Collections Explained

Abstract
This chapter will discuss the different collection types in .NET—Array, List<T>, ArrayList, Stack, Queue, Hashtable, and Dictionary—which are used for storing and managing data in an application. We will look at the internal workings of the List<T> class and how the CLR instantiates an instance of the List<T> class, how it adds items into it, and how it expands its internal array to accommodate more items. We will also examine the internal workings of the ArrayList, Stack, Queue, Hashtable, and Dictionary classes to see how CLR handles these classes to store information.
Mohammad Rahman

Chapter 12. Linq in C#

Abstract
This chapter will discuss the Language Integrated Query (Linq) in .NET and explore in detail the extension methods defined in the Enumerable class that are provided to do the Linq operation using C#. First, you will learn the basics of Linq and then examine the behind-the-scenes operations of each of the extension methods provided in the Enumerable class. Based on their delegate-based query syntax, you will learn the internal implementation of these extension methods using the help of ildasm.exe and .NET Reflector tool.
Mohammad Rahman

Chapter 13. Exception Management

Abstract
This chapter will discuss the exception and exception handling in .NET using C#. The chapter begins with the definition of exception and then explains how the CLR manages the exception in .NET by discussing exception-handling information in the Method Description table and how the CLR uses this exception-handling information to manage the exception. I will then discuss exception handling in .NET by examining the protected block and throw and rethrow statements in .NET. The chapter then explores the stack overwrite by discussing how the CLR manages the exception throughout the method call chain using the throw statement in addition to exception matching.
Mohammad Rahman

Chapter 14. Asynchrony

Abstract
A powerful new feature has been added for asynchronous programming in C# language 5.0. This new feature comes in the form of two new keywords—async and await—which are used to make the synchronous method asynchronous. When you use these two keyword in your method, the C# compiler performs a transformation of your method code to generate the appropriate code, such as stub method and state machine, to do the asynchronous operation behind the scenes. This new feature makes asynchronous programming much easier than the exiting asynchronous pattern used in .NET.
Mohammad Rahman

Chapter 15. Diagnostic Tools in .NET

Abstract
This chapter will discuss the different debugging tools used in the .NET Framework to analyze an application and its performance and to explore the source code of the application. This chapter will explore the use of many debugging tools for applications written in .NET, such as Windbg, ILDasm, .NET Reflector, and CLR Profiler.
Mohammad Rahman

Backmatter

Weitere Informationen

Premium Partner

    Bildnachweise