Thursday, October 6, 2011

A new expression requires () or [] after type compilation error

I came across the following issue when I am trying to implement a project in Visual Studio 2005 C#. Some part of the project is already developed in Visual Studio 2008 C#. The same class files are copied to use it in Visual Studio 2005.

myList = new List<string> {"Data1", "Data2", "Data3"};

This gives me an error while compiling it in Visual Studio 2005 as "A new expression requires () or [] after type".

I had a long search on this and finally I got the following solution. 


Note those {} in error message, which are part of c# 3.0 syntax. This is not related to framework version, but to the version of the language. This is because of a different version of compiler was used.

It is compiled successfully, When I try to install the Microsoft following patch.
Happy Coding...

1 comment: