C# 3.0   What’s new by  Chakravarthy http://msmvps.com/blogs/chakravarthy [email_address] Project Lead
Agenda <ul><li>What’s new in Orcas  </li></ul><ul><li>C# 3.0 </li></ul><ul><ul><li>Implicit Variables </li></ul></ul><ul><...
Pre-Requisites <ul><li>Some Programming Exp  </li></ul><ul><li>C </li></ul><ul><li>C ++ </li></ul><ul><li>.NET Basics </li...
Ur acquaintance with C# <ul><li>Using it more than 2 Yrs </li></ul><ul><li>Started Recently </li></ul><ul><li>Am new to C#...
Orcas What is ? Specialisation doesn’t mean doing extraordinary things But doing ordinary things, extraordinarily well..
Visual Studio Code Name – Orcas <ul><li>Web </li></ul><ul><ul><li>Multi version apps </li></ul></ul><ul><ul><li>CSS Design...
demo Visual Studio  Code name Orcas <ul><li>Ctrl+Tab </li></ul><ul><li>MultiVersion </li></ul><ul><li>ECMA Intellisupport ...
C# 3.0 Features If we fail to plan,  we are planning to fail
Agenda <ul><li>What’s new in Orcas  </li></ul><ul><li>C# 3.0 </li></ul><ul><ul><li>Implicit Variables </li></ul></ul><ul><...
Implicitly typed local variables <ul><li>Declared as ‘var’ – compiler will determine type while initialization </li></ul><...
Implicitly typed arrays <ul><li>Declared as ‘var’ – compiler will determine type while initialization </li></ul><ul><li>Co...
demo Implicit Variables <ul><li>Variables </li></ul><ul><li>Multiple Declaration </li></ul><ul><li>Typed Arrays </li></ul>...
Agenda <ul><li>What’s new in Orcas  </li></ul><ul><li>C# 3.0 </li></ul><ul><ul><li>Implicit Variables </li></ul></ul><ul><...
Auto implemented properties <ul><li>Compiler will create the private variables </li></ul><ul><li>Single line public proper...
Auto implemented properties Assembler will give you the code similar to the below namespace  SampleLib  {  public class  Y...
demo Property <ul><li>Property </li></ul><ul><li>Reflector </li></ul>
Agenda <ul><li>What’s new in Orcas  </li></ul><ul><li>C# 3.0 </li></ul><ul><ul><li>Implicit Variables </li></ul></ul><ul><...
Object & Collection Initializers <ul><li>Declaration and initialization at one step </li></ul><ul><li>Ease of construction...
demo Object  & Collections <ul><li>Object from a class </li></ul><ul><li>Collections from a List <> </li></ul>
Agenda <ul><li>What’s new in Orcas  </li></ul><ul><li>C# 3.0 </li></ul><ul><ul><li>Implicit Variables </li></ul></ul><ul><...
Extension Methods <ul><li>Static Methods </li></ul><ul><li>Invoked with instance method syntax </li></ul><ul><li>Declared ...
demo Extension Methods <ul><li>Reverse the given string </li></ul>
Agenda <ul><li>What’s new in Orcas  </li></ul><ul><li>C# 3.0 </li></ul><ul><ul><li>Implicit Variables </li></ul></ul><ul><...
Anonymous Types <ul><li>No class code declaration </li></ul><ul><li>Direct initialization </li></ul><ul><li>Type is omitte...
Agenda <ul><li>What’s new in Orcas  </li></ul><ul><li>C# 3.0 </li></ul><ul><ul><li>Implicit Variables </li></ul></ul><ul><...
λ   Lambda Expressions <ul><li>Extension of anonymous methods </li></ul><ul><li>Advancement of Delegates </li></ul><ul><li...
Lambda Expressions // Data source. int[] Scores = { 90, 71, 82, 93, 75, 82 }; Write me some code that returns me the count...
Lambda Expressions // Data source. string[] Projects = { “eZCap”, “iMedsoft”, “Patient Portal”, “LiveWellHRA”, “ETL”, “iMe...
λ   Lambda Expressions –  conti .. <ul><li>Improved type inference  </li></ul><ul><li>Conversion for both delegate types a...
demo Lambda Expressions <ul><li>Delegates </li></ul><ul><li>Anonymous Methods </li></ul><ul><li>Lambda Expressions </li></ul>
Agenda <ul><li>What’s new in Orcas  </li></ul><ul><li>C# 3.0 </li></ul><ul><ul><li>Implicit Variables </li></ul></ul><ul><...
Generic Delegates (Func) <ul><li>Allows to construct a method with out declaring delegate </li></ul><ul><li>5 predefined g...
demo Generic Delegates <ul><li>Func<string, string> </li></ul>
Agenda <ul><li>What’s new in Orcas  </li></ul><ul><li>C# 3.0 </li></ul><ul><ul><li>Implicit Variables </li></ul></ul><ul><...
Expression Trees <ul><li>Don’t get confuse System.LINQ.Expression with Windows.Forms </li></ul><ul><li>Allow lamda express...
demo Expression Trees <ul><li>Expression<Func<string, string>> </li></ul><ul><li>Expression.Compile </li></ul>
Q&A
For further win/win <ul><li>var  WhoIsThereNextMonth  =  new  {  </li></ul><ul><li>Default  = “Chakravarthy”,  </li></ul><...
Where to go for any technical <ul><li>Post your message at  http:// groups.msn.com/CSharpGroup </li></ul><ul><li>Drop me a...
Next ???
Upcoming SlideShare
Loading in...5
×

Cs30 New

762

Published on

This is the presentation to explain what's new in C# 3.0 programming language

Published in: Technology, Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
762
On Slideshare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
42
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Cs30 New

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

    Clipping is a handy way to collect important slides you want to go back to later.

×