C# v3.0 - Visual Studio 2008


Implicitly Typed - var

More Details


Auto Implemented Properties

The compiler automatically creates a private field to store the property variable in addition to creating the associated get and set procedures
Makes property declaration more concise when no extra logic is required in the property accessors.
Significantly reduces the amount of typing needed to define properties on types.

public class myClass 
{
   public int ID {get; set;}
   public string Name {get; set;}
}

This was added to VB.Net in Visual Studio 2010.


Anonymous Types

Provides a convenient way to encapsulate a set of read-only properties into a single object without having to explicitly define a type first
This is achieved by using implicitly typed local variables

var myType = new { Name="Simon", Age=30 }; 

The name/value pairs declare properties with initial values
Although anonymous types are classes that do not implement the IDisposable interface
These are extremely useful when using projection operators in LINQ.


Lamda Expressions

A lambda expression is an anonymous function that you can use to create delegates or expression tree types
This lets you write local functions that can be passed as arguments or returned from functions
To create a lambda expression you specify the input parameters on the left of the lambda operator with an expression or statement block on the right
This has superseded Anonymous Methods introduced in C# 2.0.
Multi-line lambda expressions were added to VB.Net in Visual Studio 2010.

string Person = peoplelist.Find(name => name.Contains("m") 

instead of

public string FindPerson(string contains, List peoplelist) 
{
   for each (string name in peoplelist)
   {
      if (name.Contains("m"))
      {
         return name;
      }
   }
   return null;
}


Anonymous Functions

A lambda expression is an anonymous function that you can use to create delegates.
An anonymous function is an inline statement or expression that can be used wherever a delegate type is expected.
A delegate with a specific signature can be declared using the Func type.

Func< string, string > 


Object Initializers

Allows you to instantiate and initialize objects in one compound statement
Let you assign values to any accessible fields or properties at creation without having to explicitely invoke a constructor

MyClass instance = new MyClass { MyField=10, MyProperty="text" }; 

instead of

MyClass instance = new MyClass(); 
instance.MyField = 10;
instance.MyProperty = "text";


Partial Methods

A partial method is a method whose signature is declared in one class but its implementation is in a different class.
There are several restrictions though:

  • partial methods must have a return type of void

  • partial methods cannot accept out parameters

  • partial methods cannot be extern

  • partial methods cannot be virtual

  • partial methods are implicitely private


Collection Initializers

This provides a shortened syntax that enables you to create a collection and populate it with an initial set of values

var myChildren = new List<Person> 
{
   new Person { Name = "Lisa"; }
   new Person { Name = "Richard"; }
}
List<int> mylist = new List<int> {0,1,2,3,4,5}; 

This was added to VB.Net in Visual Studio 2010.


Extension Methods

Classes > Extension Methods


Query Expressions

Make frequent use of anonymous types


Expression Trees

These represent code in a tree-like data structure where each node is an expression (for example a method call or a binary operation).
You can instruct the compiler to create an expression tree for you based on an anonymous lambda expression.
You can also create expression trees manually using the System.Linq.Expressions namespace.


HashSet Collection

Another useful collection class has been added called HashSet
System.Collections.Generic.HashSet
Generics > HashSet


Language Intergrated Query (LINQ)

This is a name that incorporates a wide range of general purpose querying that can be down.
There can often be a lot of complexity around the actual data.
The common sources are relational databses and XML.
LINQ provides a standardised means to query information from many different data sources.
Rather than try and add specific (relational or XML) features to help with this complexity the approach has been more general.


Language integrated query allows a single general purpose declarative query facility to be applied to not just relational or XML based data but in-memory data as well.
LINQ defines a set of general purpose standard query operators that allow the traversal, filter and projection of information to be expressed in a direct and declarative way.
These standard query operators can be found in the System.Linq namespace.
LINQ can be divided into the following categories:
Objects > LINQ to Objects - Refers to extension methods that are available for all the classes that implement the IEnumerable or IEnumerable<T> interfaces.
XML > LINQ to XML - Refers to the use of the standard query operators as well as tree specific operators.
Databases > LINQ to SQL - Refers to the use of the standard query operators as well as database specific operators.


Office Interop API Extensions

These are a set of additional interop assemblies that can be referenced to make working with COM easier.
They provide the following additional functionality:
Method Overloads
Optional Parameters
Parameterised Properties
More Details



© 2017 Better Solutions Limited. All Rights Reserved. © 2017 Better Solutions Limited

PrevNext