Linq - an overview

635 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
635
On SlideShare
0
From Embeds
0
Number of Embeds
8
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • C# 2 introduced generics, at that point, C# is feature complete for OO features
  • Next challenge to tackle after OO features is Big Data, how to reduce complexity of integrating information
  • Provide translation between database constructs and objects
  • Easy way to query data sourceExtension methods, query comprehension syntaxWay to return arbitrary resultsAnonymous types,var keywordWay to pass input dataClosures, collection and object initializers
  • http://www.paintingsoncanvas.net/print-111552-4043120/stone-age-man-making-weapon-giclee-print/
  • http://www.travelwalls.net/wallpapers/2012/08/Walt-Disney-Concert-Hall-Modern-City-Los-Angeles-California-United-States-300x420.jpg
  • http://www.efunda.com/math/bessel/images/BesselJPlot.gif
  • http://portcityfilmfestival.com/clap-board.jpg
  • http://watermarked.cutcaster.com/cutcaster-photo-100783484-Lambda-symbol-in-glass-3d.jpg
  • http://cdn.abovethelaw.com/uploads/2012/02/thank-you.jpg
  • Linq - an overview

    1. 1. Chuck Durfee, 3 October 2012
    2. 2. BIGDATA
    3. 3. Enumerable.Select( Enumerable.OrderBy( Enumerable.Where(names, s => s.Length == 5), s => s ), s => s.ToUpper()); versusnames.Where(s => s.Length == 5) .OrderBy(s => s) .Select(s => s.ToUpper())
    4. 4. , my dear Watson
    5. 5. 1.0delegate bool FilterMethod(string s);private bool IsFiveLetterName(string s) { return s.Length == 5;}public DotNet10Land(){ FilterMethod filter = IsFiveLetterName;}
    6. 6. 2.0delegate bool FilterMethod(string s);public DotNet20Land(){ FilterMethod filter = delegate(string s) { return s.Length == 5; };}
    7. 7. C# 3 = .NET 3.5delegate bool FilterMethod(string s);public DotNet35Land(){ string chuck = "chuck"; FilterMethod filter = delegate(string s) { return s != chuck && s.Length == 5; };}
    8. 8. Func// delegate bool FilterMethod(string s);public DotNet35Land(){ Func<string, bool> filter = delegate(string s) { return s.Length == 5; };}
    9. 9. Func<string, bool>Func<string, int, DateTime>Func<List<string>, int, bool>but notFunc<string, System.Void>
    10. 10. and… Action// delegate void ActionMethod(string s);public DotNet35Land(){ Action<string> action = delegate(string s) { if (s.Length != 5) throw new ArgumentException("Length != 5"); };}
    11. 11. LAMBDA EXPRESSIONSFunc<string, bool> filter = delegate(string s) {return s.Length == 5;};var filter = (string s) => {return s.Length == 5;};var filter = (string s) => s.Length == 5;var filter = (s) => s.Length == 5;var filter = s => s.Length == 5;
    12. 12. by Alonzo Church, 1930’s
    13. 13. string[] names = { "Tom", "Dick", "Harry" };names.Select((s, i) => (i + 1) + "=" + s); 1=Tom 2=Dick 3=Harry
    14. 14. int[] numbers = { 3, 5, 7 };string[] words = { "three", "five", "seven", "ignored" };IEnumerable<string> zip = 3=three numbers.Zip(words, 5=five (n, w) => n + "=" + w); 7=seven
    15. 15. IEnumerable<Order> spanishOrders =customers .Where(c => c.Country == "Spain") .SelectMany(c => c.Orders);
    16. 16. var slowQuery =from c in customersfrom p in purchases where c.ID == p.CustomerIDselect c.Name + " bought a " + p.Description;var fastQuery =from c in customersjoin p in purchases on c.ID equals p.CustomerIDselect c.Name + " bought a " + p.Description;
    17. 17. var easyToRead = from c in customers join p in purchases on c.ID equals p.CustomerID select c.Name + " bought a " + p.Description;var harderToRead = customers.Join ( purchases, c => (int?)(c.ID), p => p.CustomerID, (c, p) => ((c.Name + " bought a ") + p.Description));
    18. 18. public static class EnumerableExtensions{ public static string ToCsv<T>( this IEnumerable<T> sequence) { const string delimiter = ", "; return sequence.Aggregate( new StringBuilder(), (sb, s) => sb.Append(s + delimiter), sb => sb.ToString() .TrimEnd(delimiter.ToArray())); }} new[] { 1, 2, 3, 5, 8, 13, 20 } => 1, 2, 3, 5, 8, 13, 20
    19. 19. Chuck Durfeehttp://neontapir.com

    ×