SlideShare a Scribd company logo
1 of 13
LINQ Inside Out

ANDRIES NIEUWENHUIZE

QUADRANT SOFTWARE B.V.

    16 JANUARI 2012
Agenda

           FEATURING:
  # LINQ-WORKHORSES (PART I)
  # THE LINQ-PATTERN (PART II)


      FROM HUMAN IN CLASS
  WHERE HUMAN.ISINTERESTED()
SELECT HUMAN.EARS + HUMAN.EYES

    // MAG IK UW AANDACHT?
Introduction

 LINQ consists of:
   syntax The buildingblocks: genrics, anonymous
    types, collection- / object-
    initializers, lambdas, Ienumerable’s, type inference
  
      semantics The ideas: basic functions, lazyness / deferred
      execution, linq-pattern, parsing

     Make sure you master them both!
LINQ-Workhorses

    AGGREGATE

    PROJECTION

    FILTERING
Aggregate

 Basisfunctie
   Tekening + demo



    signature:

 T Aggregaat<T, U>(this IEnumerable<U>, T, Func<T, U, T>)

 of
 IEnumerable<U> -> T

    Synoniemen: Fold
Projection

 Basisfunctie
   Tekening + demo



    signature:

 IEnumerable<T> Projection<T, U>(this IEnumerable<U>, Func<U, T>)

 of:
 IEnumerable<U> -> IEnumerable<T>

    Synoniemen: Map, Select
Filtering

 Basisfunctie
   Tekening + demo



    signature:

 IEnumerable<T> Filtering<T>(this IEnumerable<T>, Func<T, bool>)

 of:
 IEnumerable<U> -> IEnumerable<T>

    Synoniemen: Where
The LINQ-Pattern
The LINQ-pattern

 Initializer >> [Filter] >> [Sorter] >> Projector


 Initializer     from item in collection
 [Filter         where filter(item)]
 [Sorter         orderby item.propery]
 Projector       select item + something
The LINQ-pattern Question

 Q I am trying to transform a string made of words
 starting with an uppercase letter. I want to separate
 each word with a space and keep only the first
 uppercase letter. All other letters should be lowercase.
 For example, "TheQuickBrownFox" would become "The
 quick brown fox". Obviously, I could use a simple
 foreach and build a string by checking each
 character, but I am trying to do it using LINQ. Would
 you know how to solve this elegantly using LINQ?
 Thank you for your help. (stackoverflow.com)

 Dus, "TheQuickBrownFox" -> "The Quick Brown Fox"
The LINQ-pattern Answer #1

 public string SplitAsWords(string original)
 {
     var matches = Regex.Matches(original, "[A-Z][a-z]*")
                        .Cast<Match>();
     var str = string.Join(" ", matches
                     .Select(match => match.Value));
     str = str[0] + str.Substring(1).ToLower();

     return str;
 }

 // Hier en daar wat Linq. Lastig te volgen.
The LINQ-pattern Answer #2

 string phrase = "TheQuickBrownFox";

 var invalidChars = from ch in phrase
                    where char.IsUpper(ch)
                    select ch;
 foreach (char ch in invalidChars)
 {
     int index = phrase.IndexOf(ch);
     phrase = phrase.Remove(index, 1);
     phrase = phrase.Insert(index, " " + ch);
 }

 // Projectie niet in select, maar in aparte iteratie.
The LINQ-pattern Answer #3

 string str =
 (from i in Regex.Split("TheQuickBrownFox", "")
  select Regex.IsMatch(i, "[A-Z]") ? " " + i : i)
    .Aggregate((str1, str2) => str1 + str2);

 // Volgens pattern. Filtering en projectie samen!

More Related Content

What's hot

Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingMeghaj Mallick
 
Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17OdessaFrontend
 
C# quick ref (bruce 2016)
C# quick ref (bruce 2016)C# quick ref (bruce 2016)
C# quick ref (bruce 2016)Bruce Hantover
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorJussi Pohjolainen
 
Lec 6 14_aug [compatibility mode]
Lec 6 14_aug [compatibility mode]Lec 6 14_aug [compatibility mode]
Lec 6 14_aug [compatibility mode]Palak Sanghani
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manualnikshaikh786
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++NUST Stuff
 
2.2 higher order-functions
2.2 higher order-functions2.2 higher order-functions
2.2 higher order-functionsfuturespective
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructsGopikaS12
 
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswiftSwift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswiftTomohiro Kumagai
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheoryKnoldus Inc.
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rathSANTOSH RATH
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked listVivek Bhargav
 

What's hot (20)

Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String ProcessingDynamic Objects,Pointer to function,Array & Pointer,Character String Processing
Dynamic Objects,Pointer to function,Array & Pointer,Character String Processing
 
Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17Антихрупкий TypeScript | Odessa Frontend Meetup #17
Антихрупкий TypeScript | Odessa Frontend Meetup #17
 
Function
FunctionFunction
Function
 
A taste of Functional Programming
A taste of Functional ProgrammingA taste of Functional Programming
A taste of Functional Programming
 
C# quick ref (bruce 2016)
C# quick ref (bruce 2016)C# quick ref (bruce 2016)
C# quick ref (bruce 2016)
 
C++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operatorC++: Constructor, Copy Constructor and Assignment operator
C++: Constructor, Copy Constructor and Assignment operator
 
Array strings
Array stringsArray strings
Array strings
 
Lec 6 14_aug [compatibility mode]
Lec 6 14_aug [compatibility mode]Lec 6 14_aug [compatibility mode]
Lec 6 14_aug [compatibility mode]
 
C++ lecture 03
C++   lecture 03C++   lecture 03
C++ lecture 03
 
Data structure lab manual
Data structure lab manualData structure lab manual
Data structure lab manual
 
Lecture#6 functions in c++
Lecture#6 functions in c++Lecture#6 functions in c++
Lecture#6 functions in c++
 
2.2 higher order-functions
2.2 higher order-functions2.2 higher order-functions
2.2 higher order-functions
 
Clojure basics
Clojure basicsClojure basics
Clojure basics
 
Template C++ OOP
Template C++ OOPTemplate C++ OOP
Template C++ OOP
 
C formatted and unformatted input and output constructs
C  formatted and unformatted input and output constructsC  formatted and unformatted input and output constructs
C formatted and unformatted input and output constructs
 
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswiftSwift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
Swift 3.0 で変わったところ - 厳選 13 項目 #love_swift #cswift
 
Scala categorytheory
Scala categorytheoryScala categorytheory
Scala categorytheory
 
C++11
C++11C++11
C++11
 
Ds lab manual by s.k.rath
Ds lab manual by s.k.rathDs lab manual by s.k.rath
Ds lab manual by s.k.rath
 
Lecture 6: linked list
Lecture 6:  linked listLecture 6:  linked list
Lecture 6: linked list
 

Viewers also liked

20121023 agricom presentation_linq_v05
20121023 agricom presentation_linq_v0520121023 agricom presentation_linq_v05
20121023 agricom presentation_linq_v05LINQ_Conference
 
Cleveland Silverlight Firestarter - XAML Basics
Cleveland Silverlight Firestarter - XAML BasicsCleveland Silverlight Firestarter - XAML Basics
Cleveland Silverlight Firestarter - XAML BasicsSarah Dutkiewicz
 
XAML: One Language to Rule Them All
XAML: One Language to Rule Them AllXAML: One Language to Rule Them All
XAML: One Language to Rule Them AllFrank La Vigne
 
AgShare II Presentation for LINQ 2013
AgShare II Presentation for LINQ 2013AgShare II Presentation for LINQ 2013
AgShare II Presentation for LINQ 2013Christine Geith
 
Implementation of artificial environment using direct x
Implementation of artificial environment using direct xImplementation of artificial environment using direct x
Implementation of artificial environment using direct xS.Susant Achary
 

Viewers also liked (10)

Presentatie
PresentatiePresentatie
Presentatie
 
Internationalization quadrant
Internationalization quadrantInternationalization quadrant
Internationalization quadrant
 
FSharp @ Quadrant
FSharp @ QuadrantFSharp @ Quadrant
FSharp @ Quadrant
 
20121023 agricom presentation_linq_v05
20121023 agricom presentation_linq_v0520121023 agricom presentation_linq_v05
20121023 agricom presentation_linq_v05
 
Cleveland Silverlight Firestarter - XAML Basics
Cleveland Silverlight Firestarter - XAML BasicsCleveland Silverlight Firestarter - XAML Basics
Cleveland Silverlight Firestarter - XAML Basics
 
XAML: One Language to Rule Them All
XAML: One Language to Rule Them AllXAML: One Language to Rule Them All
XAML: One Language to Rule Them All
 
Introducing WPFand XAML
Introducing WPFand XAMLIntroducing WPFand XAML
Introducing WPFand XAML
 
AgShare II Presentation for LINQ 2013
AgShare II Presentation for LINQ 2013AgShare II Presentation for LINQ 2013
AgShare II Presentation for LINQ 2013
 
TRAILER presentation at LINQ 2013
TRAILER presentation at LINQ 2013TRAILER presentation at LINQ 2013
TRAILER presentation at LINQ 2013
 
Implementation of artificial environment using direct x
Implementation of artificial environment using direct xImplementation of artificial environment using direct x
Implementation of artificial environment using direct x
 

Similar to Linq inside out

Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimizationg3_nittala
 
Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureNurjahan Nipa
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1Taisuke Oe
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptxMrhaider4
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE Saraswathi Murugan
 
Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Sheik Uduman Ali
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithmK Hari Shankar
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0BG Java EE Course
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8franciscoortin
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming languageMegha V
 

Similar to Linq inside out (20)

Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Lecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structureLecture 02: Preliminaries of Data structure
Lecture 02: Preliminaries of Data structure
 
How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1How to start functional programming (in Scala): Day1
How to start functional programming (in Scala): Day1
 
Monads in Swift
Monads in SwiftMonads in Swift
Monads in Swift
 
Cis435 week04
Cis435 week04Cis435 week04
Cis435 week04
 
Visual Programing basic lectures 7.pptx
Visual Programing basic lectures  7.pptxVisual Programing basic lectures  7.pptx
Visual Programing basic lectures 7.pptx
 
Pythonppt28 11-18
Pythonppt28 11-18Pythonppt28 11-18
Pythonppt28 11-18
 
FUNDAMENTALS OF PYTHON LANGUAGE
 FUNDAMENTALS OF PYTHON LANGUAGE  FUNDAMENTALS OF PYTHON LANGUAGE
FUNDAMENTALS OF PYTHON LANGUAGE
 
Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0Let Us Learn Lambda Using C# 3.0
Let Us Learn Lambda Using C# 3.0
 
Advance data structure & algorithm
Advance data structure & algorithmAdvance data structure & algorithm
Advance data structure & algorithm
 
PYTHON
PYTHONPYTHON
PYTHON
 
Understanding linq
Understanding linqUnderstanding linq
Understanding linq
 
Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0Algorithms with-java-advanced-1.0
Algorithms with-java-advanced-1.0
 
Of Lambdas and LINQ
Of Lambdas and LINQOf Lambdas and LINQ
Of Lambdas and LINQ
 
The STL
The STLThe STL
The STL
 
C# programming
C# programming C# programming
C# programming
 
New Functional Features of Java 8
New Functional Features of Java 8New Functional Features of Java 8
New Functional Features of Java 8
 
Lesson11
Lesson11Lesson11
Lesson11
 
LINQ.pptx
LINQ.pptxLINQ.pptx
LINQ.pptx
 
Parts of python programming language
Parts of python programming languageParts of python programming language
Parts of python programming language
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 

Linq inside out

  • 1. LINQ Inside Out ANDRIES NIEUWENHUIZE QUADRANT SOFTWARE B.V. 16 JANUARI 2012
  • 2. Agenda FEATURING: # LINQ-WORKHORSES (PART I) # THE LINQ-PATTERN (PART II) FROM HUMAN IN CLASS WHERE HUMAN.ISINTERESTED() SELECT HUMAN.EARS + HUMAN.EYES // MAG IK UW AANDACHT?
  • 3. Introduction  LINQ consists of:  syntax The buildingblocks: genrics, anonymous types, collection- / object- initializers, lambdas, Ienumerable’s, type inference  semantics The ideas: basic functions, lazyness / deferred execution, linq-pattern, parsing  Make sure you master them both!
  • 4. LINQ-Workhorses AGGREGATE PROJECTION FILTERING
  • 5. Aggregate  Basisfunctie  Tekening + demo  signature: T Aggregaat<T, U>(this IEnumerable<U>, T, Func<T, U, T>) of IEnumerable<U> -> T  Synoniemen: Fold
  • 6. Projection  Basisfunctie  Tekening + demo  signature: IEnumerable<T> Projection<T, U>(this IEnumerable<U>, Func<U, T>) of: IEnumerable<U> -> IEnumerable<T>  Synoniemen: Map, Select
  • 7. Filtering  Basisfunctie  Tekening + demo  signature: IEnumerable<T> Filtering<T>(this IEnumerable<T>, Func<T, bool>) of: IEnumerable<U> -> IEnumerable<T>  Synoniemen: Where
  • 9. The LINQ-pattern  Initializer >> [Filter] >> [Sorter] >> Projector  Initializer from item in collection  [Filter where filter(item)]  [Sorter orderby item.propery]  Projector select item + something
  • 10. The LINQ-pattern Question  Q I am trying to transform a string made of words starting with an uppercase letter. I want to separate each word with a space and keep only the first uppercase letter. All other letters should be lowercase. For example, "TheQuickBrownFox" would become "The quick brown fox". Obviously, I could use a simple foreach and build a string by checking each character, but I am trying to do it using LINQ. Would you know how to solve this elegantly using LINQ? Thank you for your help. (stackoverflow.com)  Dus, "TheQuickBrownFox" -> "The Quick Brown Fox"
  • 11. The LINQ-pattern Answer #1  public string SplitAsWords(string original) { var matches = Regex.Matches(original, "[A-Z][a-z]*") .Cast<Match>(); var str = string.Join(" ", matches .Select(match => match.Value)); str = str[0] + str.Substring(1).ToLower(); return str; }  // Hier en daar wat Linq. Lastig te volgen.
  • 12. The LINQ-pattern Answer #2  string phrase = "TheQuickBrownFox"; var invalidChars = from ch in phrase where char.IsUpper(ch) select ch; foreach (char ch in invalidChars) { int index = phrase.IndexOf(ch); phrase = phrase.Remove(index, 1); phrase = phrase.Insert(index, " " + ch); }  // Projectie niet in select, maar in aparte iteratie.
  • 13. The LINQ-pattern Answer #3  string str = (from i in Regex.Split("TheQuickBrownFox", "") select Regex.IsMatch(i, "[A-Z]") ? " " + i : i) .Aggregate((str1, str2) => str1 + str2);  // Volgens pattern. Filtering en projectie samen!