Expert C# 5.0: with the .NET 4.5 Framework (Expert's Voice in .NET)

Expert C# 5.0: with the .NET 4.5 Framework (Expert's Voice in .NET)

Mohammad Rahman

Language: English

Pages: 612

ISBN: 1430248602

Format: PDF / Kindle (mobi) / ePub

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.

Sams Teach Yourself the Twitter API in 24 Hours

Professional Node.js

The Coming Prosperity: How Entrepreneurs Are Transforming the Global Economy

HTML5 Canvas for Dummies

Dart in Action

Professional Visual Studio 2012















Figure 11-21 demonstrates the Enqueue and Dequeue operations of the Queue class. Figure 11-21. Enqueue and Dequeue operations in the Queue class The implementation of the Dequeue method is demonstrated in Listing 11-22. Listing 11-22. The implementation of the Dequeue Method of the Queue Class public virtual object Dequeue() { ŠŠŠŠobject obj2 = this._array[this._head]; ŠŠŠŠthis._array[this._head] = null; ŠŠŠŠthis._head = (this._head + 1) % this._array.Length; ŠŠŠŠthis._size--;

local in source) ŠŠŠŠ{ ŠŠŠŠŠŠŠŠif (predicate(local)) ŠŠŠŠŠŠŠŠŠŠŠŠnum += 1L; ŠŠŠŠ} ŠŠŠŠreturn num; } Max The Max extension method is used to determine the maximum number from a list. The signature of the Max method has 22 overloaded methods, with two of those being: public static int Max(this IEnumerable`intb source) public static decimal Max`TSourceb(this IEnumerable`TSourceb source, ŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠŠFunc`TSource, decimalb selector) Listing 12-33 presents an example of the

ŠŠŠŠpublic class BuiltInValuePassingAsRef ŠŠŠŠ{ ŠŠŠŠŠŠŠŠpublic BuiltInValuePassingAsRef() ŠŠŠŠŠŠŠŠ{ ŠŠŠŠŠŠŠŠŠŠŠŠConsole.WriteLine("Built in value type passing as ref"); ŠŠŠŠŠŠŠŠ} ŠŠŠŠŠŠŠŠpublic void MethodA() ŠŠŠŠŠŠŠŠ{ ŠŠŠŠŠŠŠŠŠŠŠŠint a = 10, b = 10; ŠŠŠŠŠŠŠŠŠŠŠMethodB(ref a, ref b); ŠŠŠŠŠŠŠŠŠŠŠŠConsole.WriteLine("Method A: {0},{1}", a, b); ŠŠŠŠŠŠŠŠ} ŠŠŠŠŠŠŠŠpublic void MethodB(ref int a, ref int b) ŠŠŠŠŠŠŠŠ{ ŠŠŠŠŠŠŠŠŠŠŠŠConsole.WriteLine("Method B: {0},{1}", a, b); ŠŠŠŠŠŠŠŠŠŠŠŠa *= 2; b *= 2;

ŠŠŠŠŠŠŠŠŠŠŠŠConsole.WriteLine("{0}\t{1}\t{2}", a,_a, @int); ŠŠŠŠŠŠŠŠ} ŠŠŠŠ} } This program will produce the output: 10ŠŠŠŠŠŠ20ŠŠŠŠŠŠ10 The decompiled IL code (decompiled using the ildasm.exe) of Listing 1-2 shows how the variable names, such as a, _a, and @int, are compiled by the C# compiler: .method private hidebysig static void Main(string[] args) cil managed { ŠŠŠŠ.entrypoint ŠŠŠŠ.maxstack 4 ŠŠŠŠ.locals init ( ŠŠŠŠŠŠŠŠ[0] int32ŠŠŠŠŠa,ŠŠŠŠŠŠŠŠŠ /* a compiled as a */ ŠŠŠŠŠŠŠŠ[1]

method, it generates a class, which is a state machine used to implement the behavior that is expressed in the iterator block. On each yield statement, control is returned to the caller, but the CLR maintains the state of the callee into the state machine the compiler generated for it. The iterator block can be declared as shown in Figure 9-2. Figure 9-2. Iterators declaration The return type of the iterator block is one of the following: Enumerator: System.Collections.IEnumerator or

Download sample