Chapter 2. C# and VB.NET language enhancements

 

This chapter covers:

  • Key C# 3.0 and VB.NET 9.0 languages features for LINQ
  • Implicitly typed local variables
  • Object initializers
  • Lambda expressions
  • Extension methods
  • Anonymous types

In chapter 1, we reviewed the motivation behind LINQ and introduced some code to give you an idea of what to expect. In this chapter, we’ll present the language extensions that make LINQ possible and allow queries to blend into programming languages.

LINQ extends C# and VB.NET with new constructs. We find it important that you discover these language features before we get back to LINQ content. This chapter is a stepping stone that explains how the C# and VB.NET languages have been enriched to make LINQ possible. Please note that the full-fledged features we present here can be used in contexts other than just LINQ.

We won’t go into advanced details about each feature, because we don’t want to lose our focus on LINQ for too long. You’ll be able to see all these features in action throughout this book, so you should grow accustomed to them as you read.

In chapter 3, we’ll focus on LINQ-specific concepts such as expression trees and query operators. You’ll then see how the features presented in this chapter are used by LINQ.

2.1. Discovering the new language enhancements

 

2.2. Implicitly typed local variables

var i = 5;
 
 

2.3. Object and collection initializers

new Point {X = 1, Y = 2}
 
 
 

2.4. Lambda expressions

address => address.City == "Paris"
 
 
 

2.5. Extension methods

static void Dump(this object o);
 
 
 

2.6. Anonymous types

var contact = new { Name = "Bob", Age = 8 }
 
 
 

2.7. Summary

 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage