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
// 複数のIDを管理するテク | |
// 【C# 9.0】 Source Generator回 - ufcpp https://youtu.be/QXT-TSvIbbY?t=5816 | |
var person0 = new Person(0); | |
var person1 = new Person(1); | |
var shop0 = new Shop(0); | |
System.Console.WriteLine("Check Id0 : " + (person0.Id == person1.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
// これでも問題ないけど、インテリセンスが効かなくてダサい | |
#if DEBUG | |
System.Console.WriteLine("Debug build dane."); | |
#else | |
System.Console.WriteLine("Release build dane."); | |
#endif | |
// こちらだとインテリセンスが効く | |
// しかも const 定義の if 文は IL で消してくれる (ILSpyで確認済み) | |
if (AssemblyState.IsDebugBuild) |
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
/* https://twitter.com/_midoliy_/status/1336099984962330624 | |
* | |
* 以下の書き方ができるらしい。 | |
* | |
* C#9.0 の記事を色々見てたけど初めて見た。 | |
* F# っぽい構文らしいけど、C# 側には説明ないのかな? | |
* | |
* nullチェックも行われるので、覚えていると良さげ。(SharpLabで確認) | |
* | |
* ~~~追記ここから~~~ |
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
/* - https://github.com/hsytkm/CSharpStandardSamples/blob/master/CSharpStandardSamples.Core/Spans/PooledArray.cs | |
* | |
* - Pooling large arrays with ArrayPool https://adamsitnik.com/Array-Pool/ | |
* that it has a default max array length, equal to 2^20 (1024*1024 = 1 048 576). | |
* | |
* - LitJWTに見るモダンなC#のbyte[]とSpan操作法 http://neue.cc/2019/05/27_578.html | |
* ようするに、今どきnew byte[]なんてしたら殺されるぞ! | |
* | |
* - https://gist.github.com/ufcpp/b0853cff5823d49306ba693aaa5c39fb | |
*/ |
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
#nullable enable | |
using System; | |
// tuple | |
var t = (x: 1, y: 2); | |
if (t is (x: var tx1, y: var ty1)) | |
{ | |
Console.WriteLine($"Tuple Deconstruct : x + y = {tx1 + ty1}"); |
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
// String.InternによるUnityでの省メモリ化ハック http://engineering.grani.jp/entry/2017/10/12/220409 | |
#nullable enable | |
using System; | |
using System.Text; | |
unsafe | |
{ | |
/* 1. 文字列リテラルはインターンプールに登録される。 |
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
// 非同期時代のLINQ http://neue.cc/2013/12/04_435.html | |
#nullable enable | |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Threading.Tasks; | |
static string GetName(int id) => $"Hoge {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
using System; | |
using System.Runtime.CompilerServices; | |
// static ctor を直接呼び出す(Class って名前だけど struct もOK) | |
RuntimeHelpers.RunClassConstructor(typeof(MyData).TypeHandle); | |
Console.WriteLine("end"); | |
struct MyData | |
{ |
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
// AppクラスにModelインスタンスを持たせる | |
// https://github.com/runceel/Livet-samples/blob/master/CommunicationBetweenViewModels/App.xaml.cs | |
public partial class App : Application | |
{ | |
public static new App Current => (App)Application.Current; | |
internal MyModel MyModel { get; } = new(); | |
} |
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.Reactive; | |
using System.Reactive.Linq; | |
using System.Reactive.Subjects; | |
Console.WriteLine("データ0個で完了"); | |
var subject0 = new Subject<Unit>(); | |
subject0.FirstAsync().Subscribe(new Dump<Unit>("Empty.FirstAsync")); | |
subject0.FirstOrDefaultAsync().Subscribe(new Dump<Unit>("Empty.FirstOrDefaultAsync")); | |
subject0.Take(1).Subscribe(new Dump<Unit>("Empty.Take")); |
OlderNewer