Scott Wojan

DotRant BLOG
posts - 21 , comments - 72 , trackbacks - 5

Visual Studio 2008 & .NET 3.5 Quick Changes Overview

Visual Studio 2008 & .NET 3.5 Quick Changes Overview
I AM NOT TRYING TO REPRESENT THIS WORK AS MY OWN, I AM MERELY AGGRIGATING EXISTING INFORMATION HERE FOR MY OWN BENIFIT AND MAYBE YOURS
Visual Studio 2008
General
·         Can target framework versions 2, 3, and 3.5
·         Built in ORM
ASP.NET
·         Now supports nested master pages in the designer
·         Faster switching between markup and designer
·         Split view for seeing the designer and markup at the same time
·         Drastically improved CSS support with new “Manage Styles” property window
·         ASP.NET AJAX 1.0 is now baked in
·         Built in JavaScript intellisense
o   C# style code comments for additional information via intellisense
C# Language Changes
·         Automatic Properties
o   No longer required to have a private member variables and public getter/setters. The compiler figures out what is meant by the new syntax and automatically generates it for you in the resulting IL.
Traditional Way
New Less Verbose Way
public class Person
{
    private string name;
    public string Name
    {
        get { return this.name; }
        set { this.name = value; }
    }
}
public class Person
{
    public string Name { get; set; }
}
 
·         Object Initializers
o   No longer have to build constructors for every possible way you want to initialize the object.
Traditional Way
New Less Verbose Way
public class Person
{
    private string name;
    public Person()
    {
    }
    public Person(string name)
    {
       this.name = name;
    }
    public string Name
    {
        get { return this.name; }
        set { this.name = value; }
    }
}
public class Person
{
    public string Name { get; set; }
}
//*notice no constructors are defined
Person person = new Person();
person.Name = "Scott";
 
//   -- or –
 
person.Name = new Person("Scott");
Person person = new Person();
person.Name = "Scott";
 
//-- or –-
 
person = new Person{Name = "Scott"};
//Note the use of curly braces   ^
 
·         Collection Initializers
List<Person> people = new List<Person>();
people.Add(new Person("Frank"));
people.Add(new Person("Dean"));
people.Add(new Person("Sammy"));
List<Person> people = new List<Person> {
        new Person { Name = "Scott"}
       ,new Person { Name = "Bill"}
       ,new Person { Name = "Susanne"}
};
 
·         Extension Methods
o   Allows developers to add new methods to existing CLR types.
Traditional Way
Using Extension Methods
namespace Validation
{
 public static class Validator
 {
  public static bool IsInt(string s)
  {
  Regex regex = new Regex(@"^[-+]?\d*$");
  return regex.IsMatch(s);
  }
 }
}
 
using Validation;
if (Validator.IsInteger(textBox.Text))
{
 //Do Something
}
namespace LanguageExtensions
{
 public static class StringExtensions
 {
 public static bool IsInt(this string s)
 {
  Regex regex = new Regex(@"^[-+]?\d*$");
   return regex.IsMatch(s);
 }
 }
}
 
using LanguageExtensions;
if (textBox.Text.IsInt())
{
 //Do Something
}
 
·         Anonymous Types
o   A variable’s type is inferred from its initialization
Traditional Way
Using Anonymous Types + Object Initializers
Person person = new Person();
person.Name = "Scott";
var person = new Person{Name="Scott"};
 
·         Lambda Expressions
o   A less verbose way of accomplishing anonymous methods which were introduced in 2.0
Traditional Way
Using Lambda Expressions + Anonymous Types
List<Person> people = new List<Person>();
people.Add(new Person("Bob"));
people.Add(new Person("Bobby"));
people.Add(new Person("Susanne"));
 
List<Person> filtered = people.FindAll
(
    delegate(Person p)
    {
        return p.Name.StartsWith("Bob");
    }
);
List<Person> people = new List<Person> {
        new Person { Name = "Scott"}
       ,new Person { Name = "Bill"}
       ,new Person { Name = "Susanne"}
};
var filtered2 = peeps.FindAll(p => p.Name.StartsWith("Bob"));
 
·         LINQ (Language Integrated Query)
o   LINQ is the attempt of adding the expressiveness of SQL to .NET languages
Traditional Way
Using LINQ Query Syntax
List<Person> results = new List<Person>();
foreach (Person p in people)
{
    if(p.Name.StartsWith("Bob"))
    {
        results.Add(p);
    }
}
 
//   -- or –
 
List<Person> results = people.FindAll
(
 delegate(Person p)
 {
    return p.Name.StartsWith("Bob");
 }
);
var results =
    from p in people
    where p.Name.StartsWith("Bob")
    select p;
o   Additional Examples

Print | posted on Wednesday, December 12, 2007 11:04 AM |

Feedback

Gravatar

# re: Visual Studio 2008 & .NET 3.5 Quick Changes Overview

Maybe Mark Glenn should elaborate or better... perhaps Mark Glenn could ask Mark Glenn to come up with a better list of his own and post it to help us all out.
3/7/2008 9:26 AM | wojan
Gravatar

# re: Visual Studio 2008 & .NET 3.5 Quick Changes Overview

This is very cool. Good Job
9/26/2008 9:34 PM | bkr
Gravatar

# re: Visual Studio 2008 & .NET 3.5 Quick Changes Overview

i so like this explanition,
9/9/2009 10:44 PM | marmar
Gravatar

# re: Visual Studio 2008 & .NET 3.5 Quick Changes Overview

i like this sample example, i want to get next time
9/9/2009 10:46 PM | marmar
Gravatar

# re: Visual Studio 2008 & .NET 3.5 Quick Changes Overview

Object Initializers - Traditional Way should read

person = new Person("Scott");
4/14/2010 4:47 PM | mkane
Post A Comment
Title:
Name:
Email:
Comment:
Verification:
 

Powered by: