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
| namespace ConsoleApp1 | |
| { | |
| using System.Runtime.CompilerServices; | |
| file class Gen | |
| { | |
| [InterceptsLocation(@"F:\src\ConsoleApp1\ConsoleApp1\Program.cs", 1, 16)] | |
| public static ReadOnlySpan<byte> M1(string _) => [1, 2, 3, 10, 11, 12, 100, 200, 255]; | |
| [InterceptsLocation(@"F:\src\ConsoleApp1\ConsoleApp1\Program.cs", 2, 16)] | |
| public static ReadOnlySpan<byte> M2(string _) => [0x83, 0x01, 0x01, 0x02, 0xC3, 0x61, 0x62, 0x63, 0x03, 0xA2, 0xFF, 0x00]; |
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
| // (int)Math.Floor(float.MaxValue) は、 | |
| // .NET 8 だとなぜか int.MinValue | |
| // .NET 9 だと int.MaxValue になってそう。 | |
| // .NET 9 でだけ永久ループ… | |
| M((int)Math.Floor(float.MaxValue), (int)Math.Floor(float.MaxValue)); | |
| Console.WriteLine("done."); | |
| static void M(int x, int y) |
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
| { } | |
| string[] a = []; | |
| ReadOnlySpan<object> a2 = a; // C# 13 でも OK | |
| Span<string> s = []; | |
| ReadOnlySpan<object> s2 = s; // これは 13 だとエラー。 | |
| C.M(new object[1]); // これは 13 だと ambiguous。preview だと Span っぽい。ReadOnlySpan にするみたいな話はみた。 |
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
| var a = new A(); | |
| var b = new B(); | |
| var c = new C(); | |
| // using 越し、defensive copy されたインスタンスで Dispose 呼ばれるので、元の a, b は書き変わらない。 | |
| using (a) using (b) using (c) { } | |
| Console.WriteLine(a.X); // false | |
| Console.WriteLine(b.X); // false | |
| // インターフェイスへのキャストして呼ぶのもダメ。 |
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
| 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 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
| 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 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.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 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
| 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 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.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 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
| class A(int x) | |
| { | |
| int _x = x; // これはキャプチャしない。 | |
| } | |
| class B(int x) | |
| { | |
| public int X { get; } = x; // これもキャプチャしない。 | |
| } |