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
// Unicode 8.0 | |
int ᏸ = 8; // U+13F8, Cherokee Small Letter Ye | |
// Unicode 9.0 | |
int Ɪ = 9; // U+A7AE, Small Captital I | |
// Unicode 10.0 | |
int ৼ = 10; // U+09FC, Bengali Letter Vedic Anusvara | |
// Unicode 11.0 |
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
Console.WriteLine("123".ParseOrNull<int>()); | |
Console.WriteLine("1a3".ParseOrNull<int>()); | |
static class Ex | |
{ | |
public static T? ParseOrNull<T>(this string? s, IFormatProvider? provider = null) | |
where T : struct, IParsable<T> | |
=> T.TryParse(s, provider, out var value) ? value : null; | |
} |
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
// u8 リテラルの型は ReadOnlySpan<byte> なので、ROS に対する拡張メソッド直呼び可能。 | |
""u8.R(); | |
// それでふと思ったけども、stackalloc も行ける? | |
// 式の途中で stackalloc を書くと Span になる。 | |
A.S(stackalloc byte[0]); | |
// この場合(拡張メソッドじゃなくて、静的メソッド呼びの場合)、 ReadOnlySpan への変換も働く。 | |
A.R(stackalloc byte[0]); |
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.Numerics; | |
using System.Runtime.InteropServices; | |
var a2 = new Array2<int>(); | |
for (int i = 0; i < 2; i++) a2[i] = i + 1; | |
Console.WriteLine(sum(a2.AsReadOnlySpan())); | |
var a3 = new Array3<int>(); | |
for (int i = 0; i < 3; i++) a3[i] = i + 1; |
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 Microsoft.Build.Locator; | |
using Microsoft.CodeAnalysis; | |
using Microsoft.CodeAnalysis.MSBuild; | |
class DependencyAnalyzer | |
{ | |
public static async ValueTask WriteMermaidGraph(string path) | |
{ | |
MSBuildLocator.RegisterDefaults(); | |
var workspace = MSBuildWorkspace.Create(); |
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
_ = """ | |
All whitespace characters are the same as the closing line. | |
U+20, U+2000, U+2001, U+2002, U+2003, U+2004, U+2005, U+2006, U+2007, U+2008, U+2009, U+200A, U+3000 | |
Please insert a new line here: | |
"""; |
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
ref var r = ref m(); | |
static ref int m() | |
{ | |
int i = 0; | |
return ref m1(ref i).Item1; | |
static Ref m1(scoped ref int i) => new(ref i); // A scoped ref parameter passed to new Ref() as unscoped ref. | |
} | |
#if 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
// ↓.NET 的に許されていはいるものの、 items[0] = new Base(); が例外を起こすので今となってはあんまり使いたくない機能。 | |
// 意図的に使うことはめったにないものの… | |
Base[] items1 = new Derived[1]; | |
// ↓これはミスってやっちゃうことが… | |
// (左辺からの型推論はせず、初期化側から推論して Derived[] になる。) | |
Base[] items2 = new[] { new Derived() }; | |
// items2[0] = new Base(); が問題を起こすのはまあ、有名として、 | |
// new Span<T>(), AsSpan<T>() は呼んだ時点で例外らしい。 |
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; | |
// 通貨記号を取得。 | |
static void w(CultureInfo c) | |
{ | |
var cs = c.NumberFormat.CurrencySymbol; | |
Console.WriteLine($"{c.Name}: {cs} (U+{(int)cs[0]:X4})"); | |
} | |
// 日本語環境で CurrentCulture を呼んで ja-JP カルチャーを取ってみる。 |
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
A m1() | |
{ | |
var a = new A(); | |
return a; | |
} | |
A m2(ref int x) | |
{ | |
var a = new A(); | |
a.X = ref x; |