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 System.Runtime.InteropServices; | |
class X { } | |
class Y { } | |
public class Program | |
{ | |
static void Main() | |
{ |
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
unsafe | |
{ | |
Circle circle = new() { Radius = 1 }; | |
Rectangle rectangle = new() { Width = 2, Height = 3 }; | |
Rectangle square = new() { Width = 2, Height = 2 }; | |
Console.WriteLine(Algorithm.AreaRatio(0, &circle)); | |
Console.WriteLine(Algorithm.AreaRatio(1, &rectangle)); | |
Console.WriteLine(Algorithm.AreaRatio(1, &square)); |
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
for (uint i = 0; i < 12; i++) | |
{ | |
Console.WriteLine(format(i)); | |
} | |
for (uint i = 15; i < 120; i+=7) | |
{ | |
Console.WriteLine(format(i)); | |
} | |
Console.WriteLine(format(1234)); |
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 BenchmarkDotNet.Attributes; | |
using BenchmarkDotNet.Running; | |
using System; | |
static class Lambda | |
{ | |
// Roslyn 実装では、ラムダ式に対して匿名クラスが作られて、インスタンス メソッドが作られる。 | |
// インスタンスを作る分重たそうに見えるけど、実はこの方が速い。というか静的メソッドが遅い。 | |
public static Action Nop { get; } = () => { }; | |
} |
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>netcoreapp2.0</TargetFrameworks> | |
<LangVersion>latest</LangVersion> | |
<!-- このオプションの指定で、タイムスタンプとかを決定論的なハッシュ値に置き換える --> | |
<Deterministic>true</Deterministic> | |
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 System.Collections; | |
using System.Collections.Generic; | |
// ここの using 切り替えで、どの Indexed が呼ばれるかを切り替え | |
// 手元の環境だと以下の通り(GetTotalMemory の前後差分0が理想) | |
// A: 0 | |
// B: 237568 | |
// C: 720896 |
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.Collections; | |
using System.Runtime.CompilerServices; | |
var d = new Dictionary<int, string> { { 1, "one" }, { 2, "two" } }; | |
ICovariantDictionary<int, string> cd = d.AsCovariant(); | |
// TValue が out なので string → object 代入可能。 | |
ICovariantDictionary<int, object> id = cd; | |
foreach (var (k, v) in id) |
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
namespace TimeProviderExtension; | |
public class PausableTimeProvider(TimeProvider innerProvider) : TimeProvider | |
{ | |
public PausableTimeProvider() : this(System) { } | |
private long _pausedTimestamp = innerProvider.GetTimestamp(); | |
private long _offsetTimestamp = 0; | |
private DateTimeOffset _pausedUtcNow = innerProvider.GetUtcNow(); | |
private TimeSpan _offsetUtcNow = default; |
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; | |
var p = new Private(); | |
Console.WriteLine(p.Value); // 0 | |
Accessor r = p; // implicit cast で p の参照が r に渡る。 | |
r.Value = 1; | |
Console.WriteLine(p.Value); // 書き変わってる。 | |
// PrivateProxy 触りつつ、 |
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
class A(int x) | |
{ | |
int _x = x; // これはキャプチャしない。 | |
} | |
class B(int x) | |
{ | |
public int X { get; } = x; // これもキャプチャしない。 | |
} |
NewerOlder