Visual Studio 2010 Samples for C# 4.0

These are the official samples for Visual Studio 2010 C# 4.0.

The document New Features in C# 4.0 is a high level description of the additions to the C# language, and the samples are designed to show off the new language features, particularly around the dynamic scenario.

Please submit bugs through Microsoft Connect, or provide comments on the Q/A  tab.

Visual Studio 2010 C# Samples

We break out the C# samples into two different categories:

Language Samples

The C# 4.0-specific samples are called:

Here is the complete list of language samples:


These samples help you learn LINQ quickly. They also act as a reference and guide for those with existing LINQ experience. A few handy utilities are also included. They are available in the LinqSamples folder.

LINQ Samples Database Connectivity Issues

The default connect string for the samples should work without modification if you have SQL Server Express installed on your development machine. Here is an alternate connect string that you can modify for your own purposes if you are not using SQL Express but have SQL Server available. You will probably need to modify the word test wherever it appears in the sample connect string.

string connString = 
  "server=test;database=northwind;user id=test;password=test";

On some SQL Express installations, you may not have the rights to start a user instance. If you get an error message to that effect, try removing the clause ";user instance = true" from the connection string.

Be sure that the copies of the northwind database that you are accessing are not marked read only. If necessary, browse to the copy of NORTHWIND.MDF you are trying to access, right click on the file, choose properties. Clear the Read-only attribute.

On some slow machines, or when using a virtual pc, users have reported that some database applications give errors the first time they run. Try running the sample two or three times.

The customized copies of the Northwind database included with the samples ship without an LDF (log) file. This is done intentionally, so that the LDF and MDF files do not get out of sync. When you run a sample that uses the database, or attach to the database from the Server Explorer inside Visual Studio, the LDF file will be created automatically. You may have trouble connecting to the MDF file if you are using the SQL Server Management Studio without first creating a log file.