SlideShare una empresa de Scribd logo
1 de 18
What's New in C# 3.0?  Clint Edmonson Architect Evangelist Microsoft Corporation www.notsotrivial.net
Agenda ,[object Object],[object Object],[object Object],[object Object],[object Object]
C# 3.0 - Design Themes Improves on C# 2.0 100% Backwards Compatible Language Integrated Query (LINQ)
New Features in Action
New Features in C# 3.0  Local Variable Type Inference Object Initializers Collection Initializers Anonymous Types Auto-Implemented Properties Extension Methods Lambdas Query Expressions LINQ Partial Methods
Local Variable Type Inference private static void LocalVariableTypeInference() { // Using the new 'var' keyword you can declare variables without having  // to explicity declare their type. At compile time, the compiler determines  // the type based on the assignment. int x = 10; var y = x; // Since the type inference happens at compile time, you cannot declare  // a 'var' without an assignment //var a; // Output the type name for y Console.WriteLine( y.GetType().ToString() ); }
Object Initializers private static void ObjectInitializers() { // Simplest way to create an object and set it's properties var employee1 = new Employee(); employee1.ID = 1; employee1.FirstName = "Bill"; employee1.LastName = "Gates"; Console.WriteLine( employee1.ToString() ); // We can always add a parameterized constructor to simplify coding var employee2 = new Employee( 2, "Steve", "Balmer" ); Console.WriteLine( employee2.ToString() ); // New way to create object, providing all the property value assignments // Works with any publicly accessible properties and fields var employee3 = new Employee() { ID=3, FirstName="Clint", LastName="Edmonson" }; Console.WriteLine( employee3.ToString() ); }
Collection Initializers private static void CollectionInitializers() { // Create a prepopulated list var employeeList = new List<Employee>  { new Employee { ID=1, FirstName=&quot;Bill&quot;,  LastName=&quot;Gates&quot;  }, new Employee { ID=2, FirstName=&quot;Steve&quot;, LastName=&quot;Balmer&quot;  }, new Employee { ID=3, FirstName=&quot;Clint&quot;, LastName=&quot;Edmonson&quot; } }; // Loop through and display contents of list foreach( var employee in employeeList ) { Console.WriteLine( employee.ToString() ); } }
Anonymous Types private static void AnonymousTypes() { var a = new { Name = &quot;A&quot;, Price = 3 }; Console.WriteLine( a.GetType().ToString() ); Console.WriteLine( &quot;Name = {0} : Price = {1}&quot;, a.Name, a.Price ); }
Auto-Implemented Properties public class Employee { public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } }
Extension Methods public static class StringExtensionMethods { // NOTE: When using an extension method to extend a type whose source  // code you cannot change, you run the risk that a change in the implementation // of the type will cause your extension method to break. // // If you do implement extension methods for a given type, remember the following  // two points: // - An extension method will never be called if it has the same signature  //  as a method defined in the type. // - Extension methods are brought into scope at the namespace level. For example, //  if you have multiple static classes that contain extension methods in a single  //  namespace named Extensions, they will all be brought into scope by the using  //  Extensions; namespace. // public static int WordCount( this String str ) { return str.Split( new char[] { ' ', '.', '?' },    StringSplitOptions.RemoveEmptyEntries ).Length; } } // Usage string s = &quot;Hello Extension Methods&quot;; int i = s.WordCount();
Partial Methods // Employee.cs public partial class Employee { public bool Terminated { get { return this.terminated; } set { this.terminated = value; this.OnTerminated(); } } private bool terminated; } // Employee.Customization.cs public partial class Employee { // If this method is not implemented // compiler will ignore calls to it partial void OnTerminated() { // Clear the employee's ID number this.ID = 0; } }
LINQ Expressions private static void LinqExpressions() { // Create a list of employees var employeeList = new List<Employee>  { new Employee { ID=1, FirstName=&quot;Bill&quot;,  LastName=&quot;Gates&quot;  }, new Employee { ID=2, FirstName=&quot;Steve&quot;, LastName=&quot;Balmer&quot;  }, new Employee { ID=3, FirstName=&quot;Clint&quot;, LastName=&quot;Edmonson&quot; } }; // Search the list for founders using a lambda expression var foudersByLambda = employeeList.FindAll(  employee => (employee.ID == 1 || employee.ID == 2) ); Console.WriteLine( foudersByLambda.Count.ToString() ); // Display collection using a lambda expression foudersByLambda.ForEach( employee => Console.WriteLine( employee.ToString() ) ); }
Query Expressions & Expression Trees private static void QueriesAndExpressions() { // Create a list of employees var employeeList = new List<Employee>  { new Employee { ID=1, FirstName=&quot;Bill&quot;,  LastName=&quot;Gates&quot;  }, new Employee { ID=2, FirstName=&quot;Steve&quot;, LastName=&quot;Balmer&quot;  }, new Employee { ID=3, FirstName=&quot;Clint&quot;, LastName=&quot;Edmonson&quot; } }; // Retrieve the founders via a LINQ query var query1 = from  employee in employeeList   where  employee.ID == 1 || employee.ID == 2   select employee; var founders = query1.ToList<Employee>(); founders.ForEach( founder => Console.WriteLine( founder.ToString() ) ); // Retrieve the new hires via a LINQ query that returns an anonymous type var query2 = from employee in employeeList   where employee.ID == 3   select new   { employee.FirstName, employee.LastName   }; var newHires = query2.ToList(); newHires.ForEach( newHire => Console.WriteLine( newHire.ToString() ) ); }
Best Practices ,[object Object],[object Object],[object Object],[object Object]
For More Information… ,[object Object],[object Object],[object Object],[object Object]
Questions and Answers ,[object Object],[object Object],[object Object],[object Object]
 

Más contenido relacionado

La actualidad más candente

Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
Yandex
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3
Mohamed Ahmed
 

La actualidad más candente (20)

C#.net evolution part 2
C#.net evolution part 2C#.net evolution part 2
C#.net evolution part 2
 
The Ring programming language version 1.5.2 book - Part 79 of 181
The Ring programming language version 1.5.2 book - Part 79 of 181The Ring programming language version 1.5.2 book - Part 79 of 181
The Ring programming language version 1.5.2 book - Part 79 of 181
 
C#.net Evolution part 1
C#.net Evolution part 1C#.net Evolution part 1
C#.net Evolution part 1
 
The Ring programming language version 1.2 book - Part 59 of 84
The Ring programming language version 1.2 book - Part 59 of 84The Ring programming language version 1.2 book - Part 59 of 84
The Ring programming language version 1.2 book - Part 59 of 84
 
The Ring programming language version 1.3 book - Part 62 of 88
The Ring programming language version 1.3 book - Part 62 of 88The Ring programming language version 1.3 book - Part 62 of 88
The Ring programming language version 1.3 book - Part 62 of 88
 
Swift Programming Language
Swift Programming LanguageSwift Programming Language
Swift Programming Language
 
Design Patterns in Ruby
Design Patterns in RubyDesign Patterns in Ruby
Design Patterns in Ruby
 
Denis Lebedev, Swift
Denis  Lebedev, SwiftDenis  Lebedev, Swift
Denis Lebedev, Swift
 
Introduction to Swift programming language.
Introduction to Swift programming language.Introduction to Swift programming language.
Introduction to Swift programming language.
 
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13Lecture 3, c++(complete reference,herbet sheidt)chapter-13
Lecture 3, c++(complete reference,herbet sheidt)chapter-13
 
C# Variables and Operators
C# Variables and OperatorsC# Variables and Operators
C# Variables and Operators
 
DIG1108 Lesson 6
DIG1108 Lesson 6DIG1108 Lesson 6
DIG1108 Lesson 6
 
C++ Course - Lesson 3
C++ Course - Lesson 3C++ Course - Lesson 3
C++ Course - Lesson 3
 
Class
ClassClass
Class
 
Developing iOS apps with Swift
Developing iOS apps with SwiftDeveloping iOS apps with Swift
Developing iOS apps with Swift
 
Ch7 C++
Ch7 C++Ch7 C++
Ch7 C++
 
Cocoa Design Patterns in Swift
Cocoa Design Patterns in SwiftCocoa Design Patterns in Swift
Cocoa Design Patterns in Swift
 
The Swift Compiler and Standard Library
The Swift Compiler and Standard LibraryThe Swift Compiler and Standard Library
The Swift Compiler and Standard Library
 
Quick swift tour
Quick swift tourQuick swift tour
Quick swift tour
 
Let's build a parser!
Let's build a parser!Let's build a parser!
Let's build a parser!
 

Destacado (9)

Csharp4 arrays and_tuples
Csharp4 arrays and_tuplesCsharp4 arrays and_tuples
Csharp4 arrays and_tuples
 
Csharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_eventsCsharp4 delegates lambda_and_events
Csharp4 delegates lambda_and_events
 
Secure mvc application saineshwar
Secure mvc application   saineshwarSecure mvc application   saineshwar
Secure mvc application saineshwar
 
C# language
C# languageC# language
C# language
 
Free MVC project to learn for beginners.
Free MVC project to learn for beginners.Free MVC project to learn for beginners.
Free MVC project to learn for beginners.
 
Csharp4 basics
Csharp4 basicsCsharp4 basics
Csharp4 basics
 
C# 3.5 Features
C# 3.5 FeaturesC# 3.5 Features
C# 3.5 Features
 
Introduction to .NET Core & ASP.NET Core MVC
Introduction to .NET Core & ASP.NET Core MVCIntroduction to .NET Core & ASP.NET Core MVC
Introduction to .NET Core & ASP.NET Core MVC
 
Introduction to C# 6.0 and 7.0
Introduction to C# 6.0 and 7.0Introduction to C# 6.0 and 7.0
Introduction to C# 6.0 and 7.0
 

Similar a Whats New In C# 3.0

Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
feelingspaldi
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
Jevgeni Kabanov
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
Amrit Kaur
 
Library Website
Library WebsiteLibrary Website
Library Website
gholtron
 
For C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdfFor C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdf
fathimafancyjeweller
 
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdfI am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
petercoiffeur18
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
Kiev ALT.NET
 
how do i expand upon selectionSortType so that you are no longer bou.pdf
how do i expand upon selectionSortType so that you are no longer bou.pdfhow do i expand upon selectionSortType so that you are no longer bou.pdf
how do i expand upon selectionSortType so that you are no longer bou.pdf
footwearpark
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
stn_tkiller
 
Use the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfUse the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdf
sales87
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
adityastores21
 

Similar a Whats New In C# 3.0 (20)

PostThis
PostThisPostThis
PostThis
 
Create a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdfCreate a C# applicationYou are to create a class object called “Em.pdf
Create a C# applicationYou are to create a class object called “Em.pdf
 
Embedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for JavaEmbedded Typesafe Domain Specific Languages for Java
Embedded Typesafe Domain Specific Languages for Java
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
 
Library Website
Library WebsiteLibrary Website
Library Website
 
Linq intro
Linq introLinq intro
Linq intro
 
Clean code _v2003
 Clean code _v2003 Clean code _v2003
Clean code _v2003
 
Lecture5
Lecture5Lecture5
Lecture5
 
Templates exception handling
Templates exception handlingTemplates exception handling
Templates exception handling
 
For C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdfFor C# need to make these changes to this programm, httppastebin..pdf
For C# need to make these changes to this programm, httppastebin..pdf
 
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdfI am trying to change this code from STRUCTS to CLASSES, the members.pdf
I am trying to change this code from STRUCTS to CLASSES, the members.pdf
 
Classes
ClassesClasses
Classes
 
Micro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicateMicro-ORM Introduction - Don't overcomplicate
Micro-ORM Introduction - Don't overcomplicate
 
2. Create a Java class called EmployeeMain within the same project Pr.docx
 2. Create a Java class called EmployeeMain within the same project Pr.docx 2. Create a Java class called EmployeeMain within the same project Pr.docx
2. Create a Java class called EmployeeMain within the same project Pr.docx
 
how do i expand upon selectionSortType so that you are no longer bou.pdf
how do i expand upon selectionSortType so that you are no longer bou.pdfhow do i expand upon selectionSortType so that you are no longer bou.pdf
how do i expand upon selectionSortType so that you are no longer bou.pdf
 
Library Project Phase 1
Library Project Phase 1Library Project Phase 1
Library Project Phase 1
 
Gift-VT Tools Development Overview
Gift-VT Tools Development OverviewGift-VT Tools Development Overview
Gift-VT Tools Development Overview
 
Use the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdfUse the code below from the previous assignment that we need to exte.pdf
Use the code below from the previous assignment that we need to exte.pdf
 
maincpp Build and procees a sorted linked list of Patie.pdf
maincpp   Build and procees a sorted linked list of Patie.pdfmaincpp   Build and procees a sorted linked list of Patie.pdf
maincpp Build and procees a sorted linked list of Patie.pdf
 
C++lecture9
C++lecture9C++lecture9
C++lecture9
 

Más de Clint Edmonson

Más de Clint Edmonson (20)

New Product Concept Design.pptx
New Product Concept Design.pptxNew Product Concept Design.pptx
New Product Concept Design.pptx
 
Lean & Agile Essentials
Lean & Agile EssentialsLean & Agile Essentials
Lean & Agile Essentials
 
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
MICROSOFT BLAZOR - NEXT GENERATION WEB UI OR SILVERLIGHT ALL OVER AGAIN?
 
Flow, the Universe and Everything
Flow, the Universe and EverythingFlow, the Universe and Everything
Flow, the Universe and Everything
 
Application architecture jumpstart
Application architecture jumpstartApplication architecture jumpstart
Application architecture jumpstart
 
Code smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software OdorsCode smells and Other Malodorous Software Odors
Code smells and Other Malodorous Software Odors
 
State of agile 2016
State of agile 2016State of agile 2016
State of agile 2016
 
Lean & Agile DevOps with VSTS and TFS 2015
Lean & Agile DevOps with VSTS and TFS 2015Lean & Agile DevOps with VSTS and TFS 2015
Lean & Agile DevOps with VSTS and TFS 2015
 
Application Architecture Jumpstart
Application Architecture JumpstartApplication Architecture Jumpstart
Application Architecture Jumpstart
 
Agile Metrics That Matter
Agile Metrics That MatterAgile Metrics That Matter
Agile Metrics That Matter
 
Advanced oop laws, principles, idioms
Advanced oop laws, principles, idiomsAdvanced oop laws, principles, idioms
Advanced oop laws, principles, idioms
 
Application architecture jumpstart
Application architecture jumpstartApplication architecture jumpstart
Application architecture jumpstart
 
ADO.NET Entity Framework
ADO.NET Entity FrameworkADO.NET Entity Framework
ADO.NET Entity Framework
 
Windows 8 - The JavaScript Story
Windows 8 - The JavaScript StoryWindows 8 - The JavaScript Story
Windows 8 - The JavaScript Story
 
Windows Azure Jumpstart
Windows Azure JumpstartWindows Azure Jumpstart
Windows Azure Jumpstart
 
Introduction to Windows Azure Virtual Machines
Introduction to Windows Azure Virtual MachinesIntroduction to Windows Azure Virtual Machines
Introduction to Windows Azure Virtual Machines
 
Peering through the Clouds - Cloud Architectures You Need to Master
Peering through the Clouds - Cloud Architectures You Need to MasterPeering through the Clouds - Cloud Architectures You Need to Master
Peering through the Clouds - Cloud Architectures You Need to Master
 
Architecting Scalable Applications in the Cloud
Architecting Scalable Applications in the CloudArchitecting Scalable Applications in the Cloud
Architecting Scalable Applications in the Cloud
 
Windows Azure jumpstart
Windows Azure jumpstartWindows Azure jumpstart
Windows Azure jumpstart
 
Windows Azure Virtual Machines
Windows Azure Virtual MachinesWindows Azure Virtual Machines
Windows Azure Virtual Machines
 

Último

Vip Models Escorts in Lahore 03068178123
Vip Models Escorts in Lahore 03068178123Vip Models Escorts in Lahore 03068178123
Vip Models Escorts in Lahore 03068178123
Escorts in Lahore 03068178123
 
Deira Call girl agency 0567006274 Call girls in Deira
Deira Call girl agency 0567006274 Call girls in DeiraDeira Call girl agency 0567006274 Call girls in Deira
Deira Call girl agency 0567006274 Call girls in Deira
Monica Sydney
 
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
Priya Reddy
 
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service HaridwarHaridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
ranekokila
 

Último (20)

Codes and conventions of film magazines.pptx
Codes and conventions of film magazines.pptxCodes and conventions of film magazines.pptx
Codes and conventions of film magazines.pptx
 
Osmanabad Call Girls Book Night 4k to 12k ️[8617370543] Escorts Girls Service
Osmanabad Call Girls Book Night 4k to 12k ️[8617370543] Escorts Girls ServiceOsmanabad Call Girls Book Night 4k to 12k ️[8617370543] Escorts Girls Service
Osmanabad Call Girls Book Night 4k to 12k ️[8617370543] Escorts Girls Service
 
Deira call girls 0507330913 Call girls in Deira
Deira call girls 0507330913  Call girls in DeiraDeira call girls 0507330913  Call girls in Deira
Deira call girls 0507330913 Call girls in Deira
 
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdfTop IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
Top IPTV Subscription Service to Stream Your Favorite Shows in 2024.pdf
 
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
Call Girls in Ernakulam - 9332606886 Our call girls are sure to provide you w...
 
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
Call girls Service Bellary - 9332606886 Rs 3000 Free Pickup & Drop Services 2...
 
VIP Bhiwandi Phone 8250092165 Escorts Service +Call +Girls Along With Ac Room
VIP Bhiwandi Phone 8250092165 Escorts Service +Call +Girls Along With Ac RoomVIP Bhiwandi Phone 8250092165 Escorts Service +Call +Girls Along With Ac Room
VIP Bhiwandi Phone 8250092165 Escorts Service +Call +Girls Along With Ac Room
 
Deira Call girls 0507330913 Call girls in Deira
Deira Call girls 0507330913 Call girls in DeiraDeira Call girls 0507330913 Call girls in Deira
Deira Call girls 0507330913 Call girls in Deira
 
Deira Call girls Service 0507330913 Call girls in Deira
Deira Call girls Service 0507330913  Call girls in DeiraDeira Call girls Service 0507330913  Call girls in Deira
Deira Call girls Service 0507330913 Call girls in Deira
 
Foreigner Call Girls Mahim WhatsApp +91-9833363713, Full Night Service
Foreigner Call Girls Mahim WhatsApp +91-9833363713, Full Night ServiceForeigner Call Girls Mahim WhatsApp +91-9833363713, Full Night Service
Foreigner Call Girls Mahim WhatsApp +91-9833363713, Full Night Service
 
Vip Models Escorts in Lahore 03068178123
Vip Models Escorts in Lahore 03068178123Vip Models Escorts in Lahore 03068178123
Vip Models Escorts in Lahore 03068178123
 
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Bijnor  Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Bijnor Just Call 8617370543 Top Class Call Girl Service Available
 
Deira Call girl 0506129535 Independent Call girl in Deira
Deira Call girl 0506129535  Independent Call girl in DeiraDeira Call girl 0506129535  Independent Call girl in Deira
Deira Call girl 0506129535 Independent Call girl in Deira
 
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and ModelMandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
Mandvi (Ahemdabad) Escorts 6367492432 with Real Phone number and Model
 
Bhubaneswar🌹Call Girls Kalpana Mesuem ❤Komal 9777949614 💟 Full Trusted CALL ...
Bhubaneswar🌹Call Girls Kalpana Mesuem  ❤Komal 9777949614 💟 Full Trusted CALL ...Bhubaneswar🌹Call Girls Kalpana Mesuem  ❤Komal 9777949614 💟 Full Trusted CALL ...
Bhubaneswar🌹Call Girls Kalpana Mesuem ❤Komal 9777949614 💟 Full Trusted CALL ...
 
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
Vip Call Girls Bhubaneswar 🐱‍🏍 9777949614 Independent Escorts Service Bhubane...
 
Prayagraj College Girls Escorts 8250092165 Short 1500 Night 6000 Best call g...
Prayagraj College Girls Escorts  8250092165 Short 1500 Night 6000 Best call g...Prayagraj College Girls Escorts  8250092165 Short 1500 Night 6000 Best call g...
Prayagraj College Girls Escorts 8250092165 Short 1500 Night 6000 Best call g...
 
Deira Call girl agency 0567006274 Call girls in Deira
Deira Call girl agency 0567006274 Call girls in DeiraDeira Call girl agency 0567006274 Call girls in Deira
Deira Call girl agency 0567006274 Call girls in Deira
 
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...Ghansoli Escorts Services 09167354423  Ghansoli Call Girls,Call Girls In Ghan...
Ghansoli Escorts Services 09167354423 Ghansoli Call Girls,Call Girls In Ghan...
 
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service HaridwarHaridwar Call Girls, 8699214473 Hot Girls Service Haridwar
Haridwar Call Girls, 8699214473 Hot Girls Service Haridwar
 

Whats New In C# 3.0

  • 1. What's New in C# 3.0? Clint Edmonson Architect Evangelist Microsoft Corporation www.notsotrivial.net
  • 2.
  • 3. C# 3.0 - Design Themes Improves on C# 2.0 100% Backwards Compatible Language Integrated Query (LINQ)
  • 5. New Features in C# 3.0 Local Variable Type Inference Object Initializers Collection Initializers Anonymous Types Auto-Implemented Properties Extension Methods Lambdas Query Expressions LINQ Partial Methods
  • 6. Local Variable Type Inference private static void LocalVariableTypeInference() { // Using the new 'var' keyword you can declare variables without having // to explicity declare their type. At compile time, the compiler determines // the type based on the assignment. int x = 10; var y = x; // Since the type inference happens at compile time, you cannot declare // a 'var' without an assignment //var a; // Output the type name for y Console.WriteLine( y.GetType().ToString() ); }
  • 7. Object Initializers private static void ObjectInitializers() { // Simplest way to create an object and set it's properties var employee1 = new Employee(); employee1.ID = 1; employee1.FirstName = &quot;Bill&quot;; employee1.LastName = &quot;Gates&quot;; Console.WriteLine( employee1.ToString() ); // We can always add a parameterized constructor to simplify coding var employee2 = new Employee( 2, &quot;Steve&quot;, &quot;Balmer&quot; ); Console.WriteLine( employee2.ToString() ); // New way to create object, providing all the property value assignments // Works with any publicly accessible properties and fields var employee3 = new Employee() { ID=3, FirstName=&quot;Clint&quot;, LastName=&quot;Edmonson&quot; }; Console.WriteLine( employee3.ToString() ); }
  • 8. Collection Initializers private static void CollectionInitializers() { // Create a prepopulated list var employeeList = new List<Employee> { new Employee { ID=1, FirstName=&quot;Bill&quot;, LastName=&quot;Gates&quot; }, new Employee { ID=2, FirstName=&quot;Steve&quot;, LastName=&quot;Balmer&quot; }, new Employee { ID=3, FirstName=&quot;Clint&quot;, LastName=&quot;Edmonson&quot; } }; // Loop through and display contents of list foreach( var employee in employeeList ) { Console.WriteLine( employee.ToString() ); } }
  • 9. Anonymous Types private static void AnonymousTypes() { var a = new { Name = &quot;A&quot;, Price = 3 }; Console.WriteLine( a.GetType().ToString() ); Console.WriteLine( &quot;Name = {0} : Price = {1}&quot;, a.Name, a.Price ); }
  • 10. Auto-Implemented Properties public class Employee { public int ID { get; set; } public string FirstName { get; set; } public string LastName { get; set; } }
  • 11. Extension Methods public static class StringExtensionMethods { // NOTE: When using an extension method to extend a type whose source // code you cannot change, you run the risk that a change in the implementation // of the type will cause your extension method to break. // // If you do implement extension methods for a given type, remember the following // two points: // - An extension method will never be called if it has the same signature // as a method defined in the type. // - Extension methods are brought into scope at the namespace level. For example, // if you have multiple static classes that contain extension methods in a single // namespace named Extensions, they will all be brought into scope by the using // Extensions; namespace. // public static int WordCount( this String str ) { return str.Split( new char[] { ' ', '.', '?' }, StringSplitOptions.RemoveEmptyEntries ).Length; } } // Usage string s = &quot;Hello Extension Methods&quot;; int i = s.WordCount();
  • 12. Partial Methods // Employee.cs public partial class Employee { public bool Terminated { get { return this.terminated; } set { this.terminated = value; this.OnTerminated(); } } private bool terminated; } // Employee.Customization.cs public partial class Employee { // If this method is not implemented // compiler will ignore calls to it partial void OnTerminated() { // Clear the employee's ID number this.ID = 0; } }
  • 13. LINQ Expressions private static void LinqExpressions() { // Create a list of employees var employeeList = new List<Employee> { new Employee { ID=1, FirstName=&quot;Bill&quot;, LastName=&quot;Gates&quot; }, new Employee { ID=2, FirstName=&quot;Steve&quot;, LastName=&quot;Balmer&quot; }, new Employee { ID=3, FirstName=&quot;Clint&quot;, LastName=&quot;Edmonson&quot; } }; // Search the list for founders using a lambda expression var foudersByLambda = employeeList.FindAll( employee => (employee.ID == 1 || employee.ID == 2) ); Console.WriteLine( foudersByLambda.Count.ToString() ); // Display collection using a lambda expression foudersByLambda.ForEach( employee => Console.WriteLine( employee.ToString() ) ); }
  • 14. Query Expressions & Expression Trees private static void QueriesAndExpressions() { // Create a list of employees var employeeList = new List<Employee> { new Employee { ID=1, FirstName=&quot;Bill&quot;, LastName=&quot;Gates&quot; }, new Employee { ID=2, FirstName=&quot;Steve&quot;, LastName=&quot;Balmer&quot; }, new Employee { ID=3, FirstName=&quot;Clint&quot;, LastName=&quot;Edmonson&quot; } }; // Retrieve the founders via a LINQ query var query1 = from employee in employeeList where employee.ID == 1 || employee.ID == 2 select employee; var founders = query1.ToList<Employee>(); founders.ForEach( founder => Console.WriteLine( founder.ToString() ) ); // Retrieve the new hires via a LINQ query that returns an anonymous type var query2 = from employee in employeeList where employee.ID == 3 select new { employee.FirstName, employee.LastName }; var newHires = query2.ToList(); newHires.ForEach( newHire => Console.WriteLine( newHire.ToString() ) ); }
  • 15.
  • 16.
  • 17.
  • 18.  

Notas del editor

  1. MGB 2003 © 2003 Microsoft Corporation. All rights reserved. This presentation is for informational purposes only. Microsoft makes no warranties, express or implied, in this summary. Hi, my name is Clint Edmonson Architect Evangelist based in the United States in St. Louis, Missouri. Today we’ll be talking about all the cool new language features in C# 3.0