Tutorial :c# auto property VS 2005?



Question:

Do auto-properties work in VS 2005? I can't seem to get my C# classes to compile with them (same with the in-place initialisation). I have framework 3 sp1 installed. Are these features only available in VS 2008 or is there something I am doing wrong?

By in-place initialisation i mean the following:

SomeClass c = new SomeClass()  {    Name = "",    Value = 12345  };  


Solution:1

Automatically implemented properties and object initializers (the sample you showed) were both introduced in C# 3.0. Visual Studio 2005 only compiles C# 2.0.

For more on what came in which version (and which C# 3.0 features you can use when targeting .NET 2.0), see my article on the topic.


Solution:2

No. Autoproperties are a product of the 3.5 compiler and only VS2008 can understand them.


Solution:3

You can use auto-properties in VS 2008 on projects that are targeted for .NET 2.0 as well.

You can also use lambda expressions and the var keyword.


Solution:4

Actually, with the WPF/WCF add-on for VS2005, you can create 3.0 applications. The compiler cannot utilize the 3.5 compiler though.

I used the add-on in order to create WPF applications when 3.0 released. 3.5 was exclusive to the 2008 IDE.

EDIT: What I mean to sayis the compiler that is attached to the VS2005 debugger cannot utilize them and thus you get the error at compile-time.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »