Samstag, 25. September 2021

BASTA'21 impressions - not only c#10 features...

 
https://sharplab.io/ 
-> test c# code on the fly online


https://source.dot.net/
-> observe the source code of dot net. Deep dive into the source of dot net.

github.com
githubs1.com 
-> for alternative layout of github.com; you can also push . when browsing in github.com


https://devblogs.microsoft.com/dotnet/
-> first class microsoft blogs of ms team leaders, managers, high ranking employees


record struct Vector2d(double X, double Y)
{
    public static Vector2d operator +(Vector2d first, Vector2d second) =>
        new Vector2d(first.X + second.X, first.Y + second.Y);
}
-> like normal record but value typed (variable) and not referenced typed (pointer)
-> see         https://anthonygiretti.com/2021/08/03/introducing-c-10-record-struct/


readonly record struct
-> of course - readonly - makes record struct immutable

public string FirstName { get; init; } = "Neo";
-> c# class property set init only
-> read https://www.thomasclaudiushuber.com/2020/08/25/c-9-0-init-only-properties/

with 
var v2 = v1 with { X = 4d }; // clone v1 and override double property X with new value of 4d 
-> clones the source to modify it partially
-> see : https://docs.microsoft.com/de-de/dotnet/csharp/language-reference/operators/with-expression

Remember
4d -> 4.0 double value
4m -> 4.0 decimal value
4f -> 4.0 float value

nameof(myObject)
-> get the name description of the type

is
-> var x = "my text" is String;
-> predicate operation (true/false result) if object is of type ANY. Here is x true finally.

stackalloc
-> value types are stack allocates and not pushed to the heap
-> see https://docs.microsoft.com/de-de/dotnet/csharp/language-reference/operators/stackalloc


Span<Vector2d> vectors = stackalloc Vector2d[]
{
    new Vector2d(3d, 4d),
    new Vector2d(1d, 2d)
};

-> see https://docs.microsoft.com/de-de/dotnet/api/system.span-1?view=net-5.0

and even more....