13.07.2015 Views

C# in Depth

C# in Depth

C# in Depth

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ABOUT THIS BOOKxxvtopics are often understood “just well enough” by <strong>C#</strong>1 developers, but <strong>C#</strong>2 and 3develop them significantly, so a solid ground<strong>in</strong>g is required <strong>in</strong> order to make the mostof the new features.Chapter 3 tackles the biggest feature of <strong>C#</strong>2, and potentially the hardest to grasp:generics. Methods and types can be written generically, with type parameters stand<strong>in</strong>g<strong>in</strong> for real types which are specified <strong>in</strong> the call<strong>in</strong>g code. Initially it’s as confus<strong>in</strong>g as thisdescription makes it sound, but once you understand generics you’ll wonder how yousurvived without them.If you’ve ever wanted to represent a null <strong>in</strong>teger, chapter 4 is for you. It <strong>in</strong>troducesnullable types, a feature built on generics and tak<strong>in</strong>g advantage of support <strong>in</strong> the language,runtime, and framework.Chapter 5 shows the improvements to delegates <strong>in</strong> <strong>C#</strong>2. You may have only useddelegates for handl<strong>in</strong>g events such as button clicks before now. <strong>C#</strong>2 makes it easier tocreate delegates, and library support makes them more useful for situations otherthan events.In chapter 6 we exam<strong>in</strong>e iterators, and the easy way to implement them <strong>in</strong> <strong>C#</strong>2.Few developers use iterator blocks, but as LINQ to Objects is built on iterators, theywill become more and more important. The lazy nature of their execution is also a keypart of LINQ.Chapter 7 shows a number of smaller features <strong>in</strong>troduced <strong>in</strong> <strong>C#</strong>2, each mak<strong>in</strong>g lifea little more pleasant. The language designers have smoothed over a few rough places<strong>in</strong> <strong>C#</strong>1, allow<strong>in</strong>g more flexible <strong>in</strong>teraction with code generators, better support forutility classes, more granular access to properties, and more.Chapter 8 once aga<strong>in</strong> looks at a few relatively simple features—but this time <strong>in</strong><strong>C#</strong>3. Almost all the new syntax is geared toward the common goal of LINQ but thebuild<strong>in</strong>g blocks are also useful <strong>in</strong> their own right. With anonymous types, automaticallyimplemented properties, implicitly typed local variables, and greatly enhanced<strong>in</strong>itialization support, <strong>C#</strong>3 gives a far richer language with which your code canexpress its behavior.Chapter 9 looks at the first major topic of <strong>C#</strong>3—lambda expressions. Not contentwith the reasonably concise syntax we saw <strong>in</strong> chapter 5, the language designers havemade delegates even easier to create than <strong>in</strong> <strong>C#</strong>2. Lambdas are capable of more—theycan be converted <strong>in</strong>to expression trees: a powerful way of represent<strong>in</strong>g code as data.In chapter 10 we exam<strong>in</strong>e extension methods, which provide a way of fool<strong>in</strong>g thecompiler <strong>in</strong>to believ<strong>in</strong>g that methods declared <strong>in</strong> one type actually belong to another.At first glance this appears to be a readability nightmare, but with careful considerationit can be an extremely powerful feature—and one which is vital to LINQ.Chapter 11 comb<strong>in</strong>es the previous three chapters <strong>in</strong> the form of query expressions,a concise but powerful way of query<strong>in</strong>g data. Initially we concentrate on LINQ toObjects, but see how the query expression pattern is applied <strong>in</strong> a way which allowsother data providers to plug <strong>in</strong> seamlessly.Chapter 12 reaps the rewards of query expressions comb<strong>in</strong>ed with expressiontrees: it shows how LINQ to SQL is able to convert what appears to be normal <strong>C#</strong> <strong>in</strong>toLicensed to Rhona Hadida

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!