SlideShare a Scribd company logo
C# 3.0   What’s new by  Chakravarthy http://msmvps.com/blogs/chakravarthy [email_address] Project Lead
Agenda What’s new in Orcas  C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types Lambda Expressions Generic Delegates Expression Trees Are we missing any thing here ?????
Pre-Requisites Some Programming Exp  C C ++ .NET Basics Apart of all .. Imagination is more important than knowledge .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
Ur acquaintance with C# Using it more than 2 Yrs Started Recently Am new to C# What C# is ..?
Orcas What is ? Specialisation doesn’t mean doing extraordinary things But doing ordinary things, extraordinarily well..
Visual Studio Code Name – Orcas Web Multi version apps CSS Design tools  Intellisense for ECMA Script AJAX Library Applications Templates WPF WCF WF Data Integration EDM – Entity Data Manager (ADO.NET vNext) Multi-tier Dataset Reporting Project templates
demo Visual Studio  Code name Orcas Ctrl+Tab MultiVersion ECMA Intellisupport DataIntegration(EDM) AJAX Support CSS
C# 3.0 Features If we fail to plan,  we are planning to fail
Agenda What’s new in Orcas  C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
Implicitly typed local variables Declared as ‘var’ – compiler will determine type while initialization Can only be used when declared and initialized in same statement Can’t be null Can’t be class members Used to store anonymous types as in LINQ based programming Don’t confuse with “var” at JavaScript or VB, which actually allows you to assign any type to a variable in your code Multiple declarations should evaluate at Compile time var bVal = true; var strVal = “MATUG”; Var intNum = 9; var obj =  new  {  UGName  = “Automated Test”,  url  = “http://matug.net”,  alturl =“http://groups.msn.com/matug/”}
Implicitly typed arrays Declared as ‘var’ – compiler will determine type while initialization Collection type of elements is determined by compiler var fstArry = new[] {3,6,11,78,93};    Int32 var secArry = new[] {3,6,11.48,78,93};    Double var thrArry = new[] {“Microsoft”, “MAQ”};    String var secArry = new[] {3,6,11.48,”78”,93};    Won’t compile due to irregularity in the elements
demo Implicit Variables Variables Multiple Declaration Typed Arrays Arrays Mismatch
Agenda What’s new in Orcas  C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
Auto implemented properties Compiler will create the private variables Single line public property accessor Simple object persistence mechanism Old Style private string strVar; public string EmployeeName { get{return strVar;} set{strVar = value;} } C# 3.0 public string EmployeeName { get; set; } Would you like to know what happens behind the screen ?
Auto implemented properties Assembler will give you the code similar to the below namespace  SampleLib  {  public class  YesClass {  // Fields [ CompilerGenerated ]  private  string   <>k__AutomaticallyGeneratedPropertyField0 ;  // Methods  public  YesClass (); public  void   DoNothing (); // Properties public  string   Reply   {   [ CompilerGenerated ] get;  [ CompilerGenerated ] set;  } }  }   How do you know this ? … Use any Reflector ..
demo Property Property Reflector
Agenda What’s new in Orcas  C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
Object & Collection Initializers Declaration and initialization at one step Ease of construction and initialization process Sequence of members are separated by ‘,’ Should be an accessible field assigned with = operator
demo Object  & Collections Object from a class Collections from a List <>
Agenda What’s new in Orcas  C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
Extension Methods Static Methods Invoked with instance method syntax Declared by “this” keyword as modifier Declared in “static” classes only Extension members of other kinds, such as properties, events, and operators, are being considered but are currently not supported.
demo Extension Methods Reverse the given string
Agenda What’s new in Orcas  C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
Anonymous Types No class code declaration Direct initialization Type is omitted at syntax Not only the variables but objects can also be anonymous Old Style public class Book { … } Book bkObj = new Book(); C# 3.0 Style var bkObj = new {  Title = “Harry Potter 7”, PubYr = 2007}
Agenda What’s new in Orcas  C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods Did I miss something???
λ   Lambda Expressions Extension of anonymous methods Advancement of Delegates Is an inline expression / statement block  with a concise syntax that can be used wherever a delegate or anonymous method is expected which can be used to pass arguments to method call or assign value to delegate Expression use “=>” operator Left side denotes result Right side contains statement block or expression
Lambda Expressions // Data source. int[] Scores = { 90, 71, 82, 93, 75, 82 }; Write me some code that returns me the count for the numbers that are greater than 80 ? // This query executes immediately because it returns a singleton int value, not an iterable sequence. int scoreQuery = Scores.Where(n => n > 80).Count();
Lambda Expressions // Data source. string[] Projects = { “eZCap”, “iMedsoft”, “Patient Portal”, “LiveWellHRA”, “ETL”, “iMedLiveWell”}; Write me some code that returns me the projects that has “Med” in project name ? IEnumerable<string> projsQry = from proj in projs where proj.Contains(&quot;Med&quot;) select proj; foreach (string projName in projsQry) { Console.WriteLine(projName); }
λ   Lambda Expressions –  conti .. Improved type inference  Conversion for both delegate types as well as expression trees Expression trees ?? Lambda expressions with an expression body can be converted to expression tree General rules Must contain same number of parameters as the delegate type Each parameter and return value must be implicitly convertible to its corresponding delegate parameter or delegate return type
demo Lambda Expressions Delegates Anonymous Methods Lambda Expressions
Agenda What’s new in Orcas  C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
Generic Delegates (Func) Allows to construct a method with out declaring delegate 5 predefined generic delegates Last parameter is always return type You can extend them with LINQ Func<>
demo Generic Delegates Func<string, string>
Agenda What’s new in Orcas  C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Trees Partial Methods
Expression Trees Don’t get confuse System.LINQ.Expression with Windows.Forms Allow lamda expressions as data instead of code Expression<>
demo Expression Trees Expression<Func<string, string>> Expression.Compile
Q&A
For further win/win var  WhoIsThereNextMonth  =  new  {  Default  = “Chakravarthy”,  Perhaps  = “Sarma & Siva”,  AreYou =“NotSure”, Topics =“What do you Want ??”, AnyThing =“Don’t hesitate, ASK ME” }
Where to go for any technical Post your message at  http:// groups.msn.com/CSharpGroup Drop me a line at chakravarthy.dsk@inteq Visit our sessions on “KS” Knowledge Share with out fail
Next ???

More Related Content

PPS
Coding Best Practices
PPTX
The Little Wonders of C# 6
PPT
Of Lambdas and LINQ
PPTX
More Little Wonders of C#/.NET
PPT
C#/.NET Little Pitfalls
PPTX
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
PPTX
The Dark Side Of Lambda Expressions in Java 8
PPT
Java findamentals1
Coding Best Practices
The Little Wonders of C# 6
Of Lambdas and LINQ
More Little Wonders of C#/.NET
C#/.NET Little Pitfalls
Introduction of Java 8 with emphasis on Lambda Expressions and Streams
The Dark Side Of Lambda Expressions in Java 8
Java findamentals1

What's hot (20)

PPT
Java findamentals1
PPT
Java findamentals1
PPTX
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
PPTX
10 Sets of Best Practices for Java 8
PDF
Java 8 ​and ​Best Practices
PPT
Introduction to Intermediate Java
PPTX
Functional Programming In Jdk8
PDF
Cracking OCA and OCP Java 8 Exams
PPTX
Lambda Expressions in Java 8
PPTX
Back-2-Basics: .NET Coding Standards For The Real World
PPTX
C# coding standards, good programming principles & refactoring
PDF
JDT Embraces Lambda Expressions - EclipseCon North America 2014
PPSX
Comparable and comparator – a detailed discussion
PPTX
Python Programming Basics for begginners
PPTX
Java 8 Features
PPTX
Functional programming with Java 8
PPTX
Java ce241
PDF
Introduction to Dart
PDF
Why Java Sucks and C# Rocks (Final)
PPTX
C# 6.0 - DotNetNotts
Java findamentals1
Java findamentals1
Lambda Expressions in C# From Beginner To Expert - Jaliya Udagedara
10 Sets of Best Practices for Java 8
Java 8 ​and ​Best Practices
Introduction to Intermediate Java
Functional Programming In Jdk8
Cracking OCA and OCP Java 8 Exams
Lambda Expressions in Java 8
Back-2-Basics: .NET Coding Standards For The Real World
C# coding standards, good programming principles & refactoring
JDT Embraces Lambda Expressions - EclipseCon North America 2014
Comparable and comparator – a detailed discussion
Python Programming Basics for begginners
Java 8 Features
Functional programming with Java 8
Java ce241
Introduction to Dart
Why Java Sucks and C# Rocks (Final)
C# 6.0 - DotNetNotts
Ad

Viewers also liked (7)

PPTX
Lambdas and Extension using VS2010
PPTX
C# Parallel programming
PPTX
C# 6.0
PPTX
Async Programming with C#5: Basics and Pitfalls
PPTX
Asynchronous programming
PPTX
C# 6.0 - What?! C# is being updated?
PPTX
The Psychology of C# Analysis
Lambdas and Extension using VS2010
C# Parallel programming
C# 6.0
Async Programming with C#5: Basics and Pitfalls
Asynchronous programming
C# 6.0 - What?! C# is being updated?
The Psychology of C# Analysis
Ad

Similar to Cs30 New (20)

PPT
Visual studio 2008
PPTX
PPT
Whats New In C# 3.0
PPT
Linq 1224887336792847 9
PPTX
Linq Introduction
PPT
C#3.0 & Vb 9.0 New Features
PPT
Linq To The Enterprise
PPTX
Module 2: C# 3.0 Language Enhancements (Slides)
PDF
New c sharp3_features_(linq)_part_ii
PPT
Microsoft Silverlight
ODP
Can't Dance The Lambda
PPT
Introduction to csharp
PPT
Introduction to-csharp-1229579367461426-1
PPT
Introduction To Csharp
PPT
Introduction to csharp
PPT
Introduction to csharp
PPS
Introduction to CSharp
PDF
Module 2: C# 3.0 Language Enhancements (Material)
PPTX
Notes(1).pptx
PDF
Intake 38 3
Visual studio 2008
Whats New In C# 3.0
Linq 1224887336792847 9
Linq Introduction
C#3.0 & Vb 9.0 New Features
Linq To The Enterprise
Module 2: C# 3.0 Language Enhancements (Slides)
New c sharp3_features_(linq)_part_ii
Microsoft Silverlight
Can't Dance The Lambda
Introduction to csharp
Introduction to-csharp-1229579367461426-1
Introduction To Csharp
Introduction to csharp
Introduction to csharp
Introduction to CSharp
Module 2: C# 3.0 Language Enhancements (Material)
Notes(1).pptx
Intake 38 3

More from DSK Chakravarthy (19)

PPTX
Break the ICE with DSK
PPTX
Intelligent Machines for Industry 4.0
PPTX
Initial Meetup of Hyderabad Chapter of BAI
PPTX
ROC, not ROI
PPTX
Hacking the Quality
PPTX
agile 3.0
PPT
Architectures
PPTX
ROC for DevOPs
PPTX
Cognitive agility
PPTX
Microsoft Products and Classification
PPTX
What's new in Wcf4
PPT
XML and XPath details
PPT
The Degree of Understanding
PPTX
What's new in .NET Framework v4.5
PPTX
Relat EVE estimates
PPTX
Journey to Next level Agility
PPT
It Market
PPTX
Intro Cloud Computing
PPT
Designingapplswithnet
Break the ICE with DSK
Intelligent Machines for Industry 4.0
Initial Meetup of Hyderabad Chapter of BAI
ROC, not ROI
Hacking the Quality
agile 3.0
Architectures
ROC for DevOPs
Cognitive agility
Microsoft Products and Classification
What's new in Wcf4
XML and XPath details
The Degree of Understanding
What's new in .NET Framework v4.5
Relat EVE estimates
Journey to Next level Agility
It Market
Intro Cloud Computing
Designingapplswithnet

Recently uploaded (20)

PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Encapsulation theory and applications.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
Mushroom cultivation and it's methods.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
Hybrid model detection and classification of lung cancer
PDF
A novel scalable deep ensemble learning framework for big data classification...
PPTX
OMC Textile Division Presentation 2021.pptx
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
WOOl fibre morphology and structure.pdf for textiles
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
From MVP to Full-Scale Product A Startup’s Software Journey.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Encapsulation theory and applications.pdf
MIND Revenue Release Quarter 2 2025 Press Release
Hindi spoken digit analysis for native and non-native speakers
Mushroom cultivation and it's methods.pdf
A comparative analysis of optical character recognition models for extracting...
Agricultural_Statistics_at_a_Glance_2022_0.pdf
Hybrid model detection and classification of lung cancer
A novel scalable deep ensemble learning framework for big data classification...
OMC Textile Division Presentation 2021.pptx
Group 1 Presentation -Planning and Decision Making .pptx
Digital-Transformation-Roadmap-for-Companies.pptx
TechTalks-8-2019-Service-Management-ITIL-Refresh-ITIL-4-Framework-Supports-Ou...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
NewMind AI Weekly Chronicles - August'25-Week II
Encapsulation_ Review paper, used for researhc scholars
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
WOOl fibre morphology and structure.pdf for textiles
Building Integrated photovoltaic BIPV_UPV.pdf
From MVP to Full-Scale Product A Startup’s Software Journey.pdf

Cs30 New

  • 1. C# 3.0 What’s new by Chakravarthy http://msmvps.com/blogs/chakravarthy [email_address] Project Lead
  • 2. Agenda What’s new in Orcas C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types Lambda Expressions Generic Delegates Expression Trees Are we missing any thing here ?????
  • 3. Pre-Requisites Some Programming Exp C C ++ .NET Basics Apart of all .. Imagination is more important than knowledge .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
  • 4. Ur acquaintance with C# Using it more than 2 Yrs Started Recently Am new to C# What C# is ..?
  • 5. Orcas What is ? Specialisation doesn’t mean doing extraordinary things But doing ordinary things, extraordinarily well..
  • 6. Visual Studio Code Name – Orcas Web Multi version apps CSS Design tools Intellisense for ECMA Script AJAX Library Applications Templates WPF WCF WF Data Integration EDM – Entity Data Manager (ADO.NET vNext) Multi-tier Dataset Reporting Project templates
  • 7. demo Visual Studio Code name Orcas Ctrl+Tab MultiVersion ECMA Intellisupport DataIntegration(EDM) AJAX Support CSS
  • 8. C# 3.0 Features If we fail to plan, we are planning to fail
  • 9. Agenda What’s new in Orcas C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
  • 10. Implicitly typed local variables Declared as ‘var’ – compiler will determine type while initialization Can only be used when declared and initialized in same statement Can’t be null Can’t be class members Used to store anonymous types as in LINQ based programming Don’t confuse with “var” at JavaScript or VB, which actually allows you to assign any type to a variable in your code Multiple declarations should evaluate at Compile time var bVal = true; var strVal = “MATUG”; Var intNum = 9; var obj = new { UGName = “Automated Test”, url = “http://matug.net”, alturl =“http://groups.msn.com/matug/”}
  • 11. Implicitly typed arrays Declared as ‘var’ – compiler will determine type while initialization Collection type of elements is determined by compiler var fstArry = new[] {3,6,11,78,93};  Int32 var secArry = new[] {3,6,11.48,78,93};  Double var thrArry = new[] {“Microsoft”, “MAQ”};  String var secArry = new[] {3,6,11.48,”78”,93};  Won’t compile due to irregularity in the elements
  • 12. demo Implicit Variables Variables Multiple Declaration Typed Arrays Arrays Mismatch
  • 13. Agenda What’s new in Orcas C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
  • 14. Auto implemented properties Compiler will create the private variables Single line public property accessor Simple object persistence mechanism Old Style private string strVar; public string EmployeeName { get{return strVar;} set{strVar = value;} } C# 3.0 public string EmployeeName { get; set; } Would you like to know what happens behind the screen ?
  • 15. Auto implemented properties Assembler will give you the code similar to the below namespace SampleLib { public class YesClass { // Fields [ CompilerGenerated ] private string <>k__AutomaticallyGeneratedPropertyField0 ; // Methods public YesClass (); public void DoNothing (); // Properties public string Reply { [ CompilerGenerated ] get; [ CompilerGenerated ] set; } } } How do you know this ? … Use any Reflector ..
  • 17. Agenda What’s new in Orcas C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
  • 18. Object & Collection Initializers Declaration and initialization at one step Ease of construction and initialization process Sequence of members are separated by ‘,’ Should be an accessible field assigned with = operator
  • 19. demo Object & Collections Object from a class Collections from a List <>
  • 20. Agenda What’s new in Orcas C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
  • 21. Extension Methods Static Methods Invoked with instance method syntax Declared by “this” keyword as modifier Declared in “static” classes only Extension members of other kinds, such as properties, events, and operators, are being considered but are currently not supported.
  • 22. demo Extension Methods Reverse the given string
  • 23. Agenda What’s new in Orcas C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
  • 24. Anonymous Types No class code declaration Direct initialization Type is omitted at syntax Not only the variables but objects can also be anonymous Old Style public class Book { … } Book bkObj = new Book(); C# 3.0 Style var bkObj = new { Title = “Harry Potter 7”, PubYr = 2007}
  • 25. Agenda What’s new in Orcas C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods Did I miss something???
  • 26. λ Lambda Expressions Extension of anonymous methods Advancement of Delegates Is an inline expression / statement block with a concise syntax that can be used wherever a delegate or anonymous method is expected which can be used to pass arguments to method call or assign value to delegate Expression use “=>” operator Left side denotes result Right side contains statement block or expression
  • 27. Lambda Expressions // Data source. int[] Scores = { 90, 71, 82, 93, 75, 82 }; Write me some code that returns me the count for the numbers that are greater than 80 ? // This query executes immediately because it returns a singleton int value, not an iterable sequence. int scoreQuery = Scores.Where(n => n > 80).Count();
  • 28. Lambda Expressions // Data source. string[] Projects = { “eZCap”, “iMedsoft”, “Patient Portal”, “LiveWellHRA”, “ETL”, “iMedLiveWell”}; Write me some code that returns me the projects that has “Med” in project name ? IEnumerable<string> projsQry = from proj in projs where proj.Contains(&quot;Med&quot;) select proj; foreach (string projName in projsQry) { Console.WriteLine(projName); }
  • 29. λ Lambda Expressions – conti .. Improved type inference Conversion for both delegate types as well as expression trees Expression trees ?? Lambda expressions with an expression body can be converted to expression tree General rules Must contain same number of parameters as the delegate type Each parameter and return value must be implicitly convertible to its corresponding delegate parameter or delegate return type
  • 30. demo Lambda Expressions Delegates Anonymous Methods Lambda Expressions
  • 31. Agenda What’s new in Orcas C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Methods Partial Methods
  • 32. Generic Delegates (Func) Allows to construct a method with out declaring delegate 5 predefined generic delegates Last parameter is always return type You can extend them with LINQ Func<>
  • 33. demo Generic Delegates Func<string, string>
  • 34. Agenda What’s new in Orcas C# 3.0 Implicit Variables Auto implemented properties Object & Collection Initializers Extension Methods Anonymous Types / Tuples Lambda Expressions Generic Delegates (Func) Expression Trees Partial Methods
  • 35. Expression Trees Don’t get confuse System.LINQ.Expression with Windows.Forms Allow lamda expressions as data instead of code Expression<>
  • 36. demo Expression Trees Expression<Func<string, string>> Expression.Compile
  • 37. Q&A
  • 38. For further win/win var WhoIsThereNextMonth = new { Default = “Chakravarthy”, Perhaps = “Sarma & Siva”, AreYou =“NotSure”, Topics =“What do you Want ??”, AnyThing =“Don’t hesitate, ASK ME” }
  • 39. Where to go for any technical Post your message at http:// groups.msn.com/CSharpGroup Drop me a line at chakravarthy.dsk@inteq Visit our sessions on “KS” Knowledge Share with out fail