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; // これもキャプチャしない。 | |
| } |
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
| X.M(0); // 整数リテラルの自然な型は int | |
| X.M(default); // でも、 default は「サイズが小さい型優先」っぽい | |
| // そういう仕様?意図的? | |
| class X | |
| { | |
| public static void M(int i32) { } | |
| public static void M(short i16) { } | |
| } |
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.Globalization; | |
| using System.Text.RegularExpressions; | |
| using static System.Console; | |
| var s1 = "a\u0301"; // á = a + ́ | |
| var s2 = "\u00e1"; // á | |
| // たとえ InvariantCulture でも。 | |
| // <InvariantGlobalization>false</InvariantGlobalization> な限り。 | |
| // (↑true のときは、StringComparison.Default が Ordinal になる効果もあり。) |
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.Buffers.Text; | |
| using System.Diagnostics.CodeAnalysis; | |
| using System.Runtime.InteropServices; | |
| var x = 0x12345678; | |
| Console.WriteLine($"{x.Hex()}"); | |
| public static class Format | |
| { | |
| public static AsciiBuffer8 Hex(this int 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.Buffers.Binary; | |
| var x = 0x12345678; | |
| Console.WriteLine($"{x:X}"); | |
| Console.WriteLine($"{x.Little()}"); | |
| static class LittleEndianExtensions | |
| { | |
| public static LittleEndianInt32 Little(this int x) => new(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
| class Program | |
| { | |
| static void X(bool x) { } | |
| static void X(bool x, bool y) { } | |
| static bool A<T1, T2>(int x) => true; | |
| class B { } | |
| class C { } | |
| static void Main() | |
| { |
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.Globalization; | |
| using System.Runtime.CompilerServices; | |
| Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; | |
| static string m(bool condition) => string.Create( | |
| CultureInfo.GetCultureInfo("fr-fr"), | |
| $"direct: {1.5} or {1:c}, nested: {If(condition, $"{1.5}", $"{1:C}")}"); | |
| Console.WriteLine(m(true)); |
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.Buffers; | |
| public interface IDefaultSpanFormattable : ISpanFormattable | |
| { | |
| string IFormattable.ToString(string? format, IFormatProvider? formatProvider) | |
| { | |
| var buffer = (stackalloc char[512]); | |
| if (TryFormat(buffer, out var charsWritten, format, formatProvider)) | |
| { | |
| return new string(buffer[..charsWritten]); |
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.Diagnostics.CodeAnalysis; | |
| using System.Runtime.CompilerServices; | |
| var nodes = new Node<string>[] | |
| { | |
| new("a0", 2), | |
| new("a1", 5), | |
| new("a2", 1), | |
| new("a3", -2), | |
| new("a4", 3), |
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.Text.RegularExpressions; | |
| using System.Windows; | |
| class Program | |
| { | |
| [STAThread] | |
| static void Main() | |
| { | |
| var x = Clipboard.GetText(); |