This file contains 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
// See https://aka.ms/new-console-template for more information | |
using FluentResults; | |
//1. simple | |
Console.WriteLine(Divide(5, 0)); | |
//2. fluent | |
var fluent = Result.Fail("error message 1") | |
.WithError("error message 2") |
This file contains 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
// See https://aka.ms/new-console-template for more information | |
using ConsoleApp1; | |
var nameEntities = new[] { "", null, "Dawid", "Kacper", "Wojciech", "Michał M", "Michał B", "Rafał", "Anna", "Floris" } | |
.Select(CreateUser).ToList(); | |
var index = 0; | |
foreach (var ne in nameEntities) | |
{ | |
if (ne.TryGetValue(out var u)) Console.WriteLine($"{index++}. User created: {u}"); |
This file contains 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.Runtime.CompilerServices; | |
namespace Net8.Features; | |
[Order(9)] | |
internal class InterceptorsLogging : IShowable | |
{ | |
public void Show() | |
{ | |
var todo = new TodoApi(); |
This file contains 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 BenchmarkDotNet.Attributes; | |
using Serilog; | |
namespace TestLoggerCallsPerf; | |
/*Console | |
| Method | Mean | Error | StdDev | Ratio | RatioSD | Allocated | Alloc Ratio | | |
|----------- |---------:|--------:|---------:|------:|--------:|----------:|------------:| | |
| ParamsArgs | 477.0 ms | 8.56 ms | 8.01 ms | 1.00 | 0.00 | 3.75 MB | 1.00 | |
This file contains 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFrameworks>net6.0;net7.0</TargetFrameworks> | |
</PropertyGroup> | |
<ItemGroup> | |
<PackageReference Include="BenchmarkDotNet" /> |
This file contains 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
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>net6.0</TargetFramework> | |
<ImplicitUsings>enable</ImplicitUsings> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
<ItemGroup> |
This file contains 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.Buffers; | |
namespace GenMath; | |
public static class Extensions | |
{ | |
public static TResult[] ToArray<TResult>(this Range range, Func<int, TResult> transformer) | |
{ | |
if (range.Start.IsFromEnd || range.End.IsFromEnd) throw new NotSupportedException("'FromEnd' ranges are not supported "); |
This file contains 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.Numerics; | |
namespace Benchmarks; | |
readonly struct DoubleVector | |
{ | |
private readonly double[] _values; | |
public DoubleVector(double[] values) => _values = values; | |
public double Average() |
This file contains 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
var distances = Enumerable.Range(1, 10).Select(i => new Distance(i)).ToArray(); | |
var sumOfDistances = Sum(distances); | |
var times = Enumerable.Range(1, 10).Select(i => new Time(i * i)).ToArray(); | |
var velocities = distances.Zip(times).Select(pair => pair.First / pair.Second).ToArray(); | |
static TUnit Sum<TUnit>(IEnumerable<TUnit> units) | |
where TUnit : IUnit<TUnit> |
This file contains 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
var parsedLines = Lines<CommaSeparatedWords>.Parse(""" | |
Ala,has,a,cat | |
Cat,has,Ala | |
"""); | |
var parsedNumbers = CsvFile<int>.Parse(""" | |
11 | |
22 | |
33 | |
"""); |
NewerOlder