1 / 18

Hardcore C#: Power and Flexibility

Hardcore C#: Power and Flexibility. Pavel Yosifovich CTO, Hi-Tech College http://blogs.microsoft.co.il/blogs/pavely. Quick Teaser…. What is yield ? (in C#) What does this code do? Does it compile? Why?. int yield = 6; Console.WriteLine (yield);. Agenda. Delegates & Lambdas

emma
Download Presentation

Hardcore C#: Power and Flexibility

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Hardcore C#: Power and Flexibility Pavel Yosifovich CTO, Hi-Tech College http://blogs.microsoft.co.il/blogs/pavely

  2. Quick Teaser… • What is yield? (in C#) • What does this code do? • Does it compile? Why? int yield = 6; Console.WriteLine(yield);

  3. Agenda • Delegates & Lambdas • Using & IDisposable • Iterators • Extension Methods • Q & A • Summary

  4. Demo Delegates and Lambdas

  5. Delegates And Lambdas • Anonymous Delegates / Methods • Actual method created by the compiler • Can use locals of containing method • Lambda Expressions • C# 3.0 way to express anonymous delegates

  6. IDisposable and using • GC and finalization • Deterministic finalization with IDisposable • Use using to deterministically dispose of resources • Finalizer backups up IDisposable • Can use in other ways

  7. Demo using and IDisposable

  8. using Operation using(Resourceres = newResource()) { res.DoWork(); } Resourceres = newResource(...); try { res.DoWork(); } finally { IDisposabledisp = resasIDisposable;   if(disp != null) disp.Dispose(); }

  9. What is foreach? // coll implements IEnumerable<string> foreach(stringxincoll) DoSomethingWithItem(x); IEnumerator<string> en = coll.GetEnumerator(); while(en.MoveNext()) { DoSomethingWithItem(en.Current); } IDisposabledisp = collasIDisposable; if(disp!= null) disp.Dispose();

  10. Demo Iterators

  11. Iterators • Method returning IEnumerable<T> or IEnumerator<T> • Use yieldreturnto return and suspend execution • Use yieldbreakto terminate iteration • Can be invoked without the usual foreach

  12. Demo Extension Methods

  13. Extension Methods • Static methods in a static class • First argument must be prefixed with this keyword • Method “extends” first argument type • Basis of LINQ syntax

  14. Q & A

  15. Summary • Topics covered • Delegates & Lambdas • using & IDisposable • Iterators • Extension Methods • Call to action • Explore and be creative!

  16. Related Sessions LAB04: C# 3.0 & LINQEranSharabi 14:30 – 15:40 Golan DEV403: A Deep Dive into LINQEranSharabi 16:00 – 17:10 Galil DEV402: Concurrent ProgrammingSasha Goldshtein 12:20 – 13:30 Galil

  17. Please Fill your Evaluation!

  18. © 2008 Microsoft Corporation. All rights reserved. Microsoft, Windows, Windows Vista and other product names are or may be registered trademarks and/or trademarks in the U.S. and/or other countries. The information herein is for informational purposes only and represents the current view of Microsoft Corporation as of the date of this presentation. Because Microsoft must respond to changing market conditions, it should not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot guarantee the accuracy of any information provided after the date of this presentation. MICROSOFT MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

More Related