There are lots of cases that you can improve. The examples use nullable reference types, but only the WhenNotNull
example requires it.
Consider adopting the new property pattern, wherever you use IsNullOrEmpty
.
string? hello = "hello world";
using System; | |
using System.Threading; | |
using System.Reflection; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using System.Runtime.CompilerServices; | |
public class Abstract | |
{ |
There are lots of cases that you can improve. The examples use nullable reference types, but only the WhenNotNull
example requires it.
Consider adopting the new property pattern, wherever you use IsNullOrEmpty
.
string? hello = "hello world";
public static int Entropy(this string s) | |
{ | |
if (string.IsNullOrEmpty(s)) return 0; | |
var array = ArrayPool<char>.Shared.Rent(s.Length); | |
s.CopyTo(0, array, 0, s.Length); | |
var span = array.AsSpan(0, s.Length); | |
span.Sort(); |
using System; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using BenchmarkDotNet.Attributes; | |
namespace StackTests | |
{ | |
public class TestStackSizes | |
{ | |
const int Iters = 128; |
using System; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using nint = System.Int64; | |
public class SequenceEqualThreshold | |
{ | |
static void Main(string[] args) |
using System; | |
using System.Buffers; | |
using System.Diagnostics; | |
using System.Runtime.CompilerServices; | |
using System.Runtime.InteropServices; | |
using System.Runtime.Intrinsics; | |
using System.Runtime.Intrinsics.X86; | |
using System.Text; | |
using nint = System.Int64; |
using System; | |
using System.Text.Json; | |
using System.Threading.Tasks; | |
using Microsoft.AspNetCore.Http; | |
using Microsoft.Extensions.DependencyInjection; | |
using static Microsoft.AspNetCore.Builder.ArgumentType; | |
namespace Microsoft.AspNetCore.Builder | |
{ | |
public static class RequestDelegateExtensions |
using System; | |
using System.Diagnostics; | |
using System.Net.Http; | |
using System.Threading; | |
using System.Threading.Tasks; | |
class Program | |
{ | |
const string api = "http://127.0.0.1:5001/"; |
public static class TaskExtensions | |
{ | |
public static async Task<T[]> WhenAllIgnoreErrors<T>(this Task<T>[] tasks, TimeSpan timeout) | |
{ | |
try | |
{ | |
await Task.WhenAll(tasks).TimeoutAfter(timeout).ConfigureAwait(false); | |
} | |
catch { /* ignored */ } |
using System; | |
using System.Numerics; | |
using System.Runtime.Intrinsics.X86; | |
using static System.Console; | |
class Program | |
{ | |
static void Main() | |
{ | |
FillBuckets(bucketCount: 17, values: ..17); |