Microsoft Visual Studio .NET 2010 Tips

1. Optional Parameters in C# are now supported

Optional Parameters have always been available in the CLR for VB.NET but for some reason the C# parser didn't implement it.

Example:


public void ExampleMethod(int required, string optionalstr = "default string", int optionalint = 10)
{
	Console.WriteLine(required + ", " + optionalstr + ", " + optionalint);
}

ExampleMethod(1);
ExampleMethod(1, "optional");
ExampleMethod(1, "optional", 2);

Output:
1, default string, 10
1, optional, 10
1, optional, 2

This is very handy for building query builders with optional search terms.

2. The Page Class

The two new properties added in the Page class are MetaKeyword and MetaDescription.

3. JavaScript serializer

using System.Web.Script.Serialization; // Add reference: System.Web.Extensions

If building a Windows App change the build target to .NET Framework 4, not .NET Framework 4 Client Profile.
Then add a reference to System.Web.Extensions


using System.Web.Script.Serialization;

class Person
{
    public string Name;
    public string Surname;
}

private void TestJSON()
{
    Person p = new Person();
    p.Name = "Michael";
    p.Surname = "Lynn";
    JavaScriptSerializer ser = new JavaScriptSerializer();

    Console.WriteLine(ser.Serialize(p));
}

Output:
{"Name":"Michael","Surname":"Lynn"}

4. Dynamic Data

From MSDN:
"Dynamic Data was introduced in the .NET Framework 3.5 SP1 release in mid-2008. This feature provides many enhancements for creating data-driven applications"

This is good for building quick read-only view of data in admin sites.

<asp:DynamicDataManager ID="DynamicDataManager1" runat="server"  
    AutoLoadForeignKeys="true"> 
  <DataControls> 
    <asp:DataControlReference ControlID="GridView1" /> 
  </DataControls> 
</asp:DynamicDataManager> 

<asp:GridView id="GridView1" runat="server" 
</asp:GridView>

5. ASP.NET Chart Control

This seems to support all the features of RGraph and the more basic features of FusionCharts.

RGraph requires JQuery and has to use the nocanvas JavaScript for IE8\9 but these the ASP.NET chart control may be good enough if you never have to worry about porting your code to run on Apache\PHP.

The only concern about ASP.NET 4.0 is the possibilty that it cannot or will not be installed on your production server.

Back to index.