. Automatic Property setters/getters
Whenever you declare a class, most of the times the class is used only as a placeholder with getters and setters for holding property values without any additional logic. For example, consider a simple class like the following:
public class Person
{
int _id;
string _firstName;
string _lastName;
public int ID { get{return _id;} set{_id = value;} }
public string FirstName { get{return _firstName;} set{_firstName = value;} }
public string LastName { get{return _lastName;} set{_lastName = value;} }
public string FullName { get{return FirstName + " " + LastName;} }
}
As you can see from the above class declaration, it doesn't contain any additional logic. The get and set properties are repetitive and they simply set or get the values of the properties without adding any value. In C#, you can simplify that by leveraging the new feature named Auto-Implemented properties. By taking advantage of this new feature, you can rewrite the above code as follows:
public class Person
{
public int ID { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string FullName
{
get
{
return FirstName + " " + LastName;
}
private set {;}
}
}
In the above code, when you declare a property, the compiler automatically creates a private, anonymous field that is available only to the property's get and set accessors. Note that the auto implemented properties must declare both a get and set accessor. However if you need to create a read-only property, modify the scope of the set accessor to be private.
· Object Initializers
· Collection Initializers
· Extension Methods
· Implicitly Typed Variable
· Anonymous Types
New features in asp.net 3.5
////-----------------------------
. ASP.NET AJAX
. New Controls (ListView and DataPager)
. New Data Source Control (LinqDataSource)
. LINQ (Language Integrated Query)
. ASP.NET Merge Tool:
(ASP.NET 3.5 includes a new merge tool (aspnet_merge.exe). This tool lets you combine and manage assemblies created by aspnet_compiler.exe)
. New Assemblies
· System.Core.dll - Includes the implementation for LINQ to Objects
· System.Data.Linq.dll - Includes the implementation for LINQ to SQL
· System.Xml.Linq.dll - Includes the implementation for LINQ to XML
· System.Data.DataSetExtensions.dll - Includes the implementation for LINQ to DataSet
No comments:
Post a Comment