3

I'm using the auto-implemented properties syntax in the C# source files of my ASP.NET Web Application:

public int IdUser { get; set; }
...
this.IdUser = 1;

The Target framework of the project is .NET Framework 2.0. It compile and seems to run properly on a IIS Server with only ASP.NET 2.0 installed. I use Visual Studio 2010 to develop and compile.

I understood this syntax came with .NET 3.
Did I miss a setting somewhere in VS ? Can I expect trouble deploying the website on a IIS/ASP.NET 2.0 server ?

Clément
  • 729
  • 6
  • 18
  • 1
    In case auto implemented ones the backing field is generated and pushed in by the compiler, so its very much like in case of a class you write with no constructors there is a default one pushed. – V4Vendetta Feb 22 '12 at 11:38

4 Answers4

6

Auto-implemented properties were introduced in .NET 3.0 but are backwards compatible with 2.0. That's why you can run your code on 2.0 framework. Basically, it's just a syntactic sugar and the compiler actually generates a field for you behind the scenes.

Jakub Konecki
  • 45,581
  • 7
  • 87
  • 126
1

As @Jakub said, it is backwards compatible. For example you can also use implicitly declared variables (var i = 1; //i is int), though they were also only introduced in C#3.0!

Brian Mains
  • 50,520
  • 35
  • 148
  • 257
Abbas
  • 14,186
  • 6
  • 41
  • 72
1

Automatically implemented properties works in .NET 2.0, but you won't be able to compile code in Visual Studio 2005. There is a list of 3.0 features and their compatibility with 2.0

http://csharpindepth.com/Articles/Chapter1/Versions.aspx

jpesout
  • 688
  • 5
  • 12
1

You can only run .NET 3.0/3.5 features on a server that has just .NET 2.0 if you're using a web application or a precompiled site, rather than a Visual Studio "web site," since the latter is compiled on the server, where the former are compiled by Visual Studio.

RickNZ
  • 18,448
  • 3
  • 51
  • 66