This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
ReadOnlySpan<Vector2d> vectors = stackalloc Vector2d[] { new(1d, 1d), new(2d, 2d), }; | |
Console.WriteLine(AddAll(vectors)); | |
static T AddAll<T>(ReadOnlySpan<T> addables) where T: IAddable<T> | |
{ | |
var result = T.Zero; | |
foreach (var a in addables) result += a; | |
return result; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Text; | |
var p1 = new Point(1d, 2d); | |
// p1.X = 3d; // This does not work because readonly records are immutable | |
Console.WriteLine(p1); | |
// Note: At the time of writing, deconstruct can be compiled on sharplab.io, but cannot be executed. | |
// If you want to run this code on sharplab.io, comment the following statement. | |
var (x, y) = p1; // Deconstruction works similar to record classes. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
var v1 = new Vector2d(1d, 2d); | |
v1.X = 3d; // This works because get and set are generated by default | |
Console.WriteLine(v1.X); | |
Console.WriteLine(v1); // record structs implement ToString | |
var v2 = v1 with { X = 4d }; // We can use the with keyword | |
Console.WriteLine(v2.X); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
var p = new Person("Foo", "Bar", 42); | |
// The following line does not work because records are immutable | |
// p.LastName = "Baz"; | |
Console.WriteLine(p.FirstName); | |
var b = new Product("Bike", "Mountainbike", 499m); | |
Console.WriteLine(b.Name); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="MachineMonitor.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:local="clr-namespace:MachineMonitor" | |
mc:Ignorable="d" | |
Title="Machine Monitor" Height="450" Width="800"> | |
<Window.Resources> | |
<Style TargetType="local:TemperatureChart"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window x:Class="HelloXaml.MainWindow" | |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
xmlns:local="clr-namespace:HelloXaml" | |
mc:Ignorable="d" | |
Title="MainWindow" Height="450" Width="800"> | |
<!-- | |
+=== Will become an object of this class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http"; | |
import { NgModule } from "@angular/core"; | |
import { FormsModule } from "@angular/forms"; | |
import { BrowserModule } from "@angular/platform-browser"; | |
import { | |
MsalInterceptor, | |
MsalModule, | |
MsalService, | |
MSAL_INSTANCE, | |
MSAL_INTERCEPTOR_CONFIG, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.add = function (x, y) { | |
return x + y; | |
} | |
exports.sub = function (x, y) { | |
return x - y; | |
} | |
exports.sumOfPositiveNumbers = function (upperLimitInclusive) { | |
let result = 0; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using static System.Console; | |
// We can simply replace == with is. Doesn't make much sense, though. | |
int someNumber = 42; | |
if (someNumber is 42) WriteLine("Some number is 42"); | |
// Situation changes when we change the type to object. | |
object something = 42; | |
// The following statement would not work (you cannot use == with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"strings" | |
) | |
// Generic iterator function type | |
type iteratorFunc[T any] func() *T; |