Why are my auto-implemented properties working in ASP.NET 2.0?

后端 未结 4 1827
猫巷女王i
猫巷女王i 2021-01-21 06:58

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;


        
相关标签:
4条回答
  • 2021-01-21 07:41

    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.

    0 讨论(0)
  • 2021-01-21 07:49

    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.

    0 讨论(0)
  • 2021-01-21 07:50

    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!

    0 讨论(0)
  • 2021-01-21 07:55

    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

    0 讨论(0)
提交回复
热议问题