C# 3.5 Features
Upcoming SlideShare
Loading in...5
×
 

C# 3.5 Features

on

  • 3,712 views

C# 3.5 Features

C# 3.5 Features

Statistics

Views

Total Views
3,712
Slideshare-icon Views on SlideShare
3,515
Embed Views
197

Actions

Likes
0
Downloads
50
Comments
0

17 Embeds 197

http://prabhakaransoundarapandian.blogspot.sg 71
http://prabhakaransoundarapandian.blogspot.ru 38
http://prabhakaransoundarapandian.blogspot.in 34
http://prabhakaransoundarapandian.blogspot.com 28
http://www.prabhakaransoundarapandian.blogspot.in 6
http://prabhakaransoundarapandian.blogspot.fr 4
http://prabhakaransoundarapandian.blogspot.mx 3
http://prabhakaransoundarapandian.blogspot.co.uk 2
http://www.prabhakaransoundarapandian.blogspot.com 2
http://prabhakaransoundarapandian.blogspot.de 2
http://prabhakaransoundarapandian.blogspot.it 1
http://webcache.googleusercontent.com 1
http://prabhakaransoundarapandian.blogspot.ae 1
http://prabhakaransoundarapandian.blogspot.dk 1
http://prabhakaransoundarapandian.blogspot.kr 1
http://prabhakaransoundarapandian.blogspot.com.es 1
http://prabhakaransoundarapandian.blogspot.ca 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    C# 3.5 Features C# 3.5 Features Presentation Transcript

    • .Net 3.5 -Prabhakaran
    • .Net 3.5 Framework
    • What is new in 3.5 C#? Implicitly Typed Local Variables Automatic Properties Object Initializer Collection Initializers Extension Methods Lambda Expressions Query Syntax Anonymous Types Expression Trees
    • Implicitly Typed Local VariablesExamples: var i = 5; var s = "Hello"; var d = 1.0; var numbers = new int[] {1, 2, 3}; var orders = new Dictionary<int,Order>();Are equivalent to: int i = 5; string s = "Hello"; double d = 1.0; int[] numbers = new int[] {1, 2, 3}; Dictionary<int,Order> orders = new Dictionary<int,Order>();Errors: var x; // Error, no initializer to infer type from var y = {1, 2, 3}; // Error, collection initializer not permitted var z = null; // Error, null type not permitted
    • Automatic Properties public class Person { private string _firstName; private string _lastName; private int _age; public string FirstName { get { return _firstName; } set { _firstName = value; } } public string LastName { get { return _lastName; } set { _lastName = value; } } public int Age { get { return _age; } set { _age = value; } } }
    •  For example, using automatic properties I can now re-write the code above to just be: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } } Or If I want to be really terse, I can collapse the whitespace even further like so: public class Person { public string FirstName { get; set; } public string LastName { get; set; } public int Age { get; set; } }
    • Object Initializer Person person = new Person(); person.FirstName = "Scott"; person.LastName = "Guthrie"; person.Age = 32;3.5 Person person = new Person { FirstName="Scott", LastName="Guthrie", Age=32 }; Person person = new Person { FirstName = "Scott", LastName = "Guthrie" Age = 32, Address = new Address { Street = "One Microsoft Way", City = "Redmond", State = "WA", Zip = 98052 } };
    • Collection InitializersList<Person> people = new List<Person>(); people.Add( new Person { FirstName = "Scott", LastName = "Guthrie", Age = 32 } ); people.Add( new Person { FirstName = "Bill", LastName = "Gates", Age= 50 } ); people.Add( new Person { FirstName = "Susanne", LastName = "Guthrie", Age = 32 } );3.5List<Person> people = new List<Person> { new Person { FirstName = "Scott", LastName = "Guthrie", Age = 32 }, new Person { FirstName = "Bill", LastName = "Gates", Age = 50 }, new Person { FirstName = "Susanne", LastName = "Guthrie", Age = 32} };
    • Extension MethodsExtension methods allow developers to add new methods to the public contract of anexisting CLR type, without having to sub-class it or recompile the original type.Example:string email = Request.QueryString["email"];if ( EmailValidator.IsValid(email) ) {}3.5string email = Request.QueryString["email"];if ( email.IsValidEmailAddress() ) {}public static class ScottGuExtensions{ public static bool IsValidEmailAddress(this string s) { Regex regex = new Regex(@"^[w-.]+@([w-]+.)+[w-]{2,4}$"); return regex.IsMatch(s); }}
    • Lambda Expressions
    • Query Syntax Query syntax is a convenient declarative shorthand for expressing queries using the standard LINQ query operators.
    • Anonymous Types