Skip to content

Instantly share code, notes, and snippets.

@ufcpp
Created November 12, 2024 23:29
Show Gist options
  • Save ufcpp/dbfd9926b2e1721c280088434f838ac1 to your computer and use it in GitHub Desktop.
Save ufcpp/dbfd9926b2e1721c280088434f838ac1 to your computer and use it in GitHub Desktop.
VS 17.13 preview 1 に First-class Span 入ってる (LangVersion preview)
{ }
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 にするみたいな話はみた。
new int[1].Ex(); // 13 だと拡張メソッドでの T[] → ROS<T> 変換は見てくれない。
static class C
{
public static void M(ReadOnlySpan<object> s) { }
public static void M(Span<object> s) { }
public static void M(IEnumerable<object> s) { }
public static void Ex(this ReadOnlySpan<int> _) { }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment