ref struct interfaces
Opened this issue · 5 comments
ufcpp commented
https://ufcpp.net/study/csharp/resource/refstruct/ に追記。
https://ufcpp.net/blog/2024/2/ref-struct-interface/ をベースに。
ページ改めてもいいかも。
済: allows (アンチ制約)の話だけ↓に追加でもいいかも。
https://ufcpp.net/study/csharp/sp2_generics.html#where
ufcpp commented
memo:
ref struct Node<T>
{
public T Value;
public ref Node<T> Next; // これ行けるようになるんだっけ?
}
ufcpp commented
allow ref struct だけ C# 13 入り。
インターフェイス実装は preview のままらしい。
ufcpp commented
Action とかのデリゲートが一通り。
その結果、ラムダ式の自然な型にも変更が:
var a1 = (Span<int> x) => 1;
Console.WriteLine(a1.GetType().Name); // Func`2 になった。
IComparer とかの比較系のインターフェイスも一通り。
一番うれしいのは AlternateLookup かも。
Dictionary<string, int> d = new(StringComparer.Ordinal) { { "key", 1 } };
var alt = d.GetAlternateLookup<string, int, ReadOnlySpan<char>>();
alt.TryGetValue("key".AsSpan(), out var value);
Console.WriteLine(value);
ufcpp commented
ufcpp commented
先に「アンチ制約」の説明だけ追加
https://ufcpp.net/study/csharp/sp2_generics.html#anti-constraint