Dixin's Blog
Microsoft Most Valuable Professional (CodingOnWheels.com) & Photographer (PicturesOnWheels.com). Code examples: GitHub.com/Dixin/Blog.
-
LINQ to XML in Depth (1) Modeling XML
XML (eXtensible Markup Language) is widely used to represent, store, and transfer data. Since .NET 3.5, the built in LINQ to XML APIs are provided to enable LINQ queries for XML data source. These APIs are located in System.Xml.XDocument NuGet package for .NET Core, and System.Xml.Linq.dll for .NET Framework. LINQ to XML can be viewed as specialized LINQ to Objects, where the objects in memory represents XML structures.
-
LINQ to Objects in Depth (7) Custom Query Methods
After discussing the query methods provided by .NET, this part demonstrates how to define custom query methods:
-
LINQ to Objects in Depth (6) Interactive Extensions (Ix)
Besides the built-in query methods (standard query operators) provided by System.Linq.Enumerable, Microsoft also provides additional query methods through the System.Interactive NuGet package (aka Interactive Extensions (Ix) library), which has a System.Linq.EnumerableEx type with the following query methods:
-
LINQ to Objects in Depth (5) Query Methods Implementation
Understanding of internals of query methods is very helpful for using them accurately and effectively, and is also helpful for defining custom query methods, which is discussed later in this chapter. Just like the usage discussion part, here query methods are still categorized by returned type, but in a different order:
-
LINQ to Objects in Depth (4) Deferred Execution, Lazy Evaluation and Eager Evaluation
As fore mentioned, when a generator method (method contains yield statement and returns IEnumerable<T>) is compiled to a pure function, which constructs a generator and return it to caller. So at runtime, when a generator method is called, the values in output sequence is not pulled or evaluated. This is called deferred execution.
-
LINQ to Objects in Depth (3) Generator
After understanding how to use LINQ to Objects, starting from this part, the implementation of query methods is discussed. Most LINQ to Object query methods are implemented with iteration pattern and generators.
-
LINQ to Objects in Depth (2) Query Methods (Operators) and Query Expressions
This part discusses the usages of built-in LINQ to Objects query methods and query expressions. As fore mentioned, these query methods (also called standard query operators) are provided in System.Linq.Enumerable type, most of which are IEnumerable<T> extension methods. They can be categorized by return type:
-
LINQ to Objects in Depth (1) Local Sequential Query
LINQ to Objects queries sequences of .NET objects in local memory of current .NET application or service. Its data source and the queries are represented by IEnumerable<T>.
-
C# Functional Programming In-Depth (15) Pattern matching
Pattern matching is a common feature in functional languages. C# 7.0 introduces basic pattern matching, including constant value as pattern and type as pattern, and C# 7.1 supports generics in pattern matching.
-
C# Functional Programming In-Depth (14) Asynchronous Function
Asynchronous function can improve the responsiveness and scalability of the application and service. C# 5.0 introduces async and await keywords to greatly simplify the async programming model.
-
C# Functional Programming In-Depth (13) Pure Function
Functional programming encourages modeling operations with pure functions.
-
C# Functional Programming In-Depth (12) Immutability, Anonymous Type, and Tuple
Immutability is an important aspect of functional paradigm. As fore mentioned, imperative/object-oriented programming is usually stateful, and functional programming encourages immutability without state change. In C# programming, there are many kinds of immutability, but they can be categorized into 2 levels: immutability of some value, and immutability of some value’s internal state. Take local variable as example, a local variable can be called immutable, if once it is assigned, there is no way to reassign to it; a local variable can also be called immutable, if once its internal state is initialized, there is no way to modify its state to different state.
-
C# Functional Programming In-Depth (11) Covariance and Contravariance
In covariance and contravariance, variance means the capability to substitute a type with a more derived type or less derived type in a context. The following is a simple inheritance hierarchy:
-
C# Functional Programming In-Depth (10) Query Expression
C# 3.0 introduces query expression, a SQL-like query syntactic sugar for query methods composition.
-
C# Functional Programming In-Depth (9) Function Composition and Chaining
In object-oriented programming, objects can be composed to build more complex object. Similarly, in functional programming. functions can be composed to build more complex function.
-
C# Functional Programming In-Depth (8) Higher-order Function, Currying and First Class Function
Higher-order function is a function accepting one or more function parameters as input, or returning a function as output. The other functions are called first-order functions. C# supports higher-order function from the beginning. Generally, C# function can have almost any data type and function type as its input types and output type, except:
-
C# Functional Programming In-Depth (7) Expression Tree: Function as Data
C# lambda expression is a powerful syntactic sugar. Besides representing anonymous function, the same syntax can also represent expression tree.
-
C# Functional Programming In-Depth (6) Anonymous Function and Lambda Expression
Besides named function represented by method members, C# also supports anonymous functions, represented by anonymous method or lambda expression with no name at design time. This part discussed lambda expression as a functional feature of C# language. In the meanwhile, the general concept of lambda expression is the core of lambda calculus, where functional programming originates. General lambda expression and lambda calculus will be discussed in the Lambda Calculus chapter.
-
C# functional programming in-depth (5) Delegate: Function type, instance and group
In C#, functions are represented by methods of types, and other function members of types. In C#, just like just objects have types, methods/functions have types too, which are represented by delegate type.
-
C# functional programming in-depth (4) Function input and output
In C#, by default, arguments are passed to parameters by value. In the following example, the PassByValue function has a Uri parameter and a int type parameter. Uri is class so it is reference type, and int is structure so it is value type: