Merge branch 'main' into NET-6

This commit is contained in:
Marcello 2021-09-20 21:38:57 +02:00
commit c04f26cf04
86 changed files with 847 additions and 878 deletions

View file

@ -160,4 +160,4 @@ protected async void MyButton_Click(object sender, EventArgs e)
// We may actually be on another *thread*, but we have the same ASP.NET request context.
Response.Write("File downloaded!");
}
```
```

View file

@ -2,9 +2,9 @@
## Arrays
An array is an object that contains multiple elements of a particular type. The number of elements is fixed for the lifetime of the array, so it must be specied when the array is created.
An array is an object that contains multiple elements of a particular type. The number of elements is fixed for the lifetime of the array, so it must be specified when the array is created.
An array type is always a reference type, regardless of the element type. Nonetheless, the choice between reference type and value type elements makes a significant difference in an arrays behavior.
An array type is always a reference type, regardless of the element type. Nonetheless, the choice between reference type and value type elements makes a significant difference in an array's behavior.
```cs
type[] array = new type[dimension];
@ -14,9 +14,9 @@ type[] array = {value1, value2, ..., valueN}; // initializer
var array = new type[] {value1, value2, ..., valueN}; // initializer (var type needs new operator)
var array = new[] {value1, value2, ..., valueN}; // initializer w/ element type inference (var type needs new operator), can be used as method arg
array[index]; // value acces
array[index] = value; // value assignement
array.Lenght; // dimension of the array
array[index]; // value access
array[index] = value; // value assignment
array.Length; // dimension of the array
// from IEnumerable<T>
array.OfType<Type>(); // filter array based on type, returns IEnumerable<Type>
@ -27,17 +27,17 @@ array.OfType<Type>(); // filter array based on type, returns IEnumerable<Type>
```cs
// overloaded search methods
Array.IndexOf(array, item); // return index of searched item in passed array
Array.LastIndexOf(array, item); // return index of searched item staring from the end of the arrary
Array.LastIndexOf(array, item); // return index of searched item staring from the end of the array
Array.FindIndex(array, Predicate<T>) // returns the index of the first item matching the predicate (can be lambda function)
Array.FindLastIndex(array, Predicate<T>) // returns the index of the last item matching the predicate (can be lambda function)
Array.Find(array, Predicate<T>) // returns the value of the first item matching the predicate (can be lambda function)
Array.FindLast(array, Predicate<T>) // returns the value of the last item matvhing the predicate (can be lambda function)
Array.FindLast(array, Predicate<T>) // returns the value of the last item matching the predicate (can be lambda function)
Array.FindAll(array, Predicate<T>) // returns array of all items matching the predicate (can be lambda function)
Array.BinarySearch(array, value) // Searches a SORTED array for a value, using a binary search algorithm; retuns the index of the found item
Array.BinarySearch(array, value) // Searches a SORTED array for a value, using a binary search algorithm; returns the index of the found item
Array.Sort(array);
Array.Reverse(array); // reverses the order of array elements
Array.Clear(start_index, x); //removes reference to x elements starting at start index. Dimension of array uncanged (cleared elements value is set tu null)
Array.Clear(start_index, x); //removes reference to x elements starting at start index. Dimension of array unchanged (cleared elements value is set tu null)
Array.Resize(ref array, target_dimension); //expands or shrinks the array dimension. Shrinking drops trailing values. Array passed by reference.
// Copies elements from an Array starting at the specified index and pastes them to another Array starting at the specified destination index.
@ -78,8 +78,8 @@ type[,] matrix = new type[n, m]; // n * m matrix
type[,] matrix = {{}, {}, {}, ...}; // {} for each row to initialize
type[, ,] tensor = new type[n, m, o] // n * m * o tensor
matrix.Length; // total numeber of elements (n * m)
matrix.GetLenght(int dimension); // get the size of a particular direction
matrix.Length; // total number of elements (n * m)
matrix.GetLength(int dimension); // get the size of a particular direction
// row = 0, column = 1, ...
```
@ -102,13 +102,13 @@ list.Insert(index, item); // insert an item at the specified index
list.InsertRange(index, item); // insert items at the specified index
list.IndexOf(item); // return index of searched item in passed list
list.LastIndexOf(item); // return index of searched item staring from the end of the arrary
list.LastIndexOf(item); // return index of searched item staring from the end of the array
list.FindIndex(Predicate<T>) // returns the index of the first item matching the predicate (can be lambda function)
list.FindLastIndex(Predicate<T>) // returns the index of the last item matching the predicate (can be lambda function)
list.Find(Predicate<T>) // returns the value of the first item matching the predicate (can be lambda function)
list.FindLast(Predicate<T>) // returns the value of the last item matvhing the predicate (can be lambda function)
list.FindLast(Predicate<T>) // returns the value of the last item matching the predicate (can be lambda function)
list.FindAll(Predicate<T>) // returns list of all items matching the predicate (can be lambda function)
list.BinarySearch(value) // Searches a SORTED list for a value, using a binary search algorithm; retuns the index of the found item
list.BinarySearch(value) // Searches a SORTED list for a value, using a binary search algorithm; returns the index of the found item
list.Remove(item); // remove item from list
list.RemoveAt(index); // remove item at specified position
@ -138,7 +138,7 @@ When a `yield return` statement is reached, the current location in code is reme
It's possible to use a `yield break` statement or exception to end the iteration.
**Note**: Since an iteartor returns an `IEnumerable<T>` is can be used to implement a `GetEnumerator()`.
**Note**: Since an iterator returns an `IEnumerable<T>` is can be used to implement a `GetEnumerator()`.
```cs
// simple iterator
@ -159,7 +159,7 @@ Exposes the enumerator, which supports a simple iteration over a collection of a
```cs
public interface IEnumerable<out T> : IEnumerable
{
IEnumerator<T> GetEnumerator(); // retrun an enumerator
IEnumerator<T> GetEnumerator(); // return an enumerator
}
// iterate through a collection
@ -227,7 +227,7 @@ Span<T> slice = array[start..end];
ReadOnlySpan<T> slice = array[start..end];
```
## [Dictioanaries](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2)
## [Dictionaries](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2)
[ValueCollection](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.valuecollection)
[KeyCollection](https://docs.microsoft.com/en-us/dotnet/api/system.collections.generic.dictionary-2.keycollection)
@ -258,10 +258,10 @@ Dictionary<TKey, TValue> dict =
}
// indexer access
dict[key]; // read value associted with key (throws KeyNotFoundException if key does not exist)
dict[key] = value; // modify value associted with key (throws KeyNotFoundException if key does not exist)
dict[key]; // read value associated with key (throws KeyNotFoundException if key does not exist)
dict[key] = value; // modify value associated with key (throws KeyNotFoundException if key does not exist)
dict.Count; // numer of key-value pair stored in the dict
dict.Count; // number of key-value pair stored in the dict
dict.Keys; // Dictionary<TKey,TValue>.KeyCollection containing the keys of the dict
dict.Values; // Dictionary<TKey,TValue>.ValueCollection containing the values of the dict

View file

@ -11,7 +11,7 @@ LINQ to Objects will be used when any `IEnumerable<T>` is specified as the sourc
### Query Expressions
All query expressions are required to begin with a `from` clause, which specifies the source of the query.
The final part of the query is a `select` (or `group`) clause. This determines the final output of the query and its sytem type.
The final part of the query is a `select` (or `group`) clause. This determines the final output of the query and its system type.
```cs
// query expression
@ -21,10 +21,10 @@ var result = from item in enumerable select item;
var result = from item in enumerable where condition select item;
// ordering
var result = from item in enumerable orderby item.property select item; // ordered IEnumerble
var result = from item in enumerable orderby item.property select item; // ordered IEnumerable
// let clause, assign expression to variable to avoid re-evaluetion on each cycle
var result = from item in enumerable let tmp = <sub-expr> ... // BEWARE: compiled code has a lot of overhead to satisfy let caluse
// let clause, assign expression to variable to avoid re-evaluation on each cycle
var result = from item in enumerable let tmp = <sub-expr> ... // BEWARE: compiled code has a lot of overhead to satisfy let clause
// grouping (difficult to re-implement to obtain better performance)
var result = from item in enumerable group item by item.property; // returns IEnumerable<IGrouping<TKey,TElement>>
@ -71,7 +71,7 @@ IEnumerable<T>.Any(Func<T, bool> predicate); // check if condition is true for
IEnumerable<T>.Concat(IEnumerable<T> enumerable);
// Applies a specified function to the corresponding elements of two sequences, producing a sequence of the results.
IEnumerable<TFirst>.Zip(IEnumerable<TSecond> enumerable, Func<TFirst, TSecoind, TResult> func);
IEnumerable<TFirst>.Zip(IEnumerable<TSecond> enumerable, Func<TFirst, TSecond, TResult> func);
IEnumerable<TFirst>.Zip(IEnumerable<TSecond> enumerable); // Produces a sequence of tuples with elements from the two specified sequences.
```

View file

@ -3,7 +3,7 @@
The **Reactive Extensions** for .NET, or **Rx**, are designed for working with asynchronous and event-based sources of information.
Rx provides services that help orchestrate and synchronize the way code reacts to data from these kinds of sources.
Rxs fundamental abstraction, `IObservable<T>`, represents a sequence of items, and its operators are defined as extension methods for this interface.
Rx's fundamental abstraction, `IObservable<T>`, represents a sequence of items, and its operators are defined as extension methods for this interface.
This might sound a lot like LINQ to Objects, and there are similarities, not only does `IObservable<T>` have a lot in common with `IEnumerable<T>`, but Rx also supports almost all of the standard LINQ operators.
@ -12,7 +12,7 @@ of an Rx source demand to be given the next item. Instead, Rx uses a *push* mode
Because Rx implements standard LINQ operators, it's possible to write queries against a live source. Rx goes beyond standard LINQ, adding its own operators that take into account the temporal nature of a live event source.
## Foundamental Interfaces
## Fundamental Interfaces
The two most important types in Rx are the `IObservable<T>` and `IObserver<T>` interfaces.
They are important enough to be in the System namespace. The other parts of Rx are in the `System.Reactive` NuGet package.