Open ufcpp opened 5 months ago
「core 内告知だとノイズ多すぎて通知受け取れない」という意見あり、announcements リポジトリに移りそう? 「discussion は core、リリースしたよは announcements でもやるからそっちを通知受け取って」かな。
enum TabOrSpace : ushort
{
Tab = '\t',
Space = ' ',
}
var options = new JsonSerializerOptions
{
WriteIndented = true,
IndentCharacter = '\t',
IndentSize = 1, // 4 space と比べると4分の1(UTF-8)
};
string[] strs = ["abc", "def", "alpha", "beta", "one", "two"];
int[] nums = [1, 2, 3, 4, 5];
foreach (var (key, count) in strs
.CountBy(x => x[0] == 'a'))
{
Console.WriteLine((key, count));
}
//strs.Select((i, x) => (i, x))
foreach (var (index, value) in nums.Index())
{
Console.WriteLine($"{index}: {value}");
}
for (int index = 0; index < nums.Length; ++index)
{
var value = nums[index];
Console.WriteLine($"{index}: {value}");
}
// コレクション初期化子は拡張メソッド受け付ける。
Dictionary<string, int> dict = new()
{
("a", 1),
("b", 2),
("c", 3)
};
// コレクション"式"は拡張メソッド受け付け"ない"。
Dictionary<string, int> dict =
[
("a", 1),
("b", 2),
("c", 3)
];
// ちなみに、将来計画: ディクショナリ式。
//[
// "a": 1,
// "b": 2,
// "c": 3
//];
static class Ex
{
public static void Add(this Dictionary<string, int> dict, (string key, int value) t)
{
dict.Add(t.key, t.value);
}
}
// 候補は List<int> か ReadOnlySpan<int> か
// まだ結論出てない。
var x = [1, 2, 3, 4];
// ↓これが ROS になってるなら、var の方は List でもいいかも。
foreach (var i in [1, 2, 3, 4])
{
Console.WriteLine(i);
}
// できるようにする予定。
// 型確定前に拡張メソッド探す。
var x = [1, 2, 3, 4].AsList();
var x = [1, 2, 3, 4].AsList();
// ↑ができるのであれば、
// ↓が変なの解消できるのでは?
Ex.M($"{1}"); // handler の方に行く
$"{1}".M(); // string の方に行く
static class Ex
{
public static void M(this string _) { }
public static void M(this IFormattable _) { }
public static void M(this DefaultInterpolatedStringHandler _) { }
}
Span<int> s = [];
// 行ける。暗黙の型変換かかる。
Ex.M(s);
// 行ける。明示的なので。
((ReadOnlySpan<int>)s).M();
// 今ダメ。
// 拡張メソッドルックアップでも暗黙の型変換調べるのやるかも。
s.M();
static class Ex
{
public static void M(this ReadOnlySpan<int> _) { }
}
string[] x = [];
ReadOnlySpan<string> y = x;
ReadOnlySpan<object> obj = y; // なんでダメやねん!
bool b = true;
int[] x0 = []; // これ推論できるでしょ。
A a = b ? new() : default; // これも推論できるでしょ。
// これ行ける
int[] x1 = b ? [1] : [];
// これも行ける。条件演算子の第3項から第2項を推論。
string[] x2 = ["a", .. (b ? ["c"] : new string[0])];
// だったらこれも行けていいでしょ。
string[] x3 = ["a", .. (b ? ["c"] : [])];
// あと、これも natural type 決めたい。
foreach (var x in [1, 2, 3]) { }
class A;
using System.Collections.Immutable;
// これダメ。Add ない。
//ArraySegment<int> a1 = [1];
// これいける。empty [] に Add 要件ない。
ArraySegment<int> a2 = [];
// ただし、現状、単に new() 扱いで、中身 null。
Console.WriteLine(a2.Array == null); // true
// 忌まわしき new() は null
ImmutableArray<int> a3 = new();
Console.WriteLine(a3 == default); // true
ImmutableArray<int> a4 = [];
Console.WriteLine(a4 == default); // false
Span<int> s1 = new();
Console.WriteLine(s1 == default); // true
Span<int> s2 = [];
Console.WriteLine(s2 == default); // true
Span<int> s3 = Array.Empty<int>();
Console.WriteLine(s3 == default); // false
using System.Collections;
// コレクション初期化子はがば
var x = new C { 1 };
class C : IEnumerable // なぜか IEnumerable 必須。
// Calculator.Add みたいなのを拾わないようにするためにわざと。
{
public void Add(int i) { }
// ダミー実装でOK。
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
}
using System.Collections;
// コレクション初期化子はがば
var x = new C { 1 };
C1 z = [1]; // 行ける
C y = [1]; // いけない
// ↑これ、C# 13 で行けるようにするかも。
// 今: IEnumerable<T> の T から型決定してる。
// 13: Add の引数見る。
class C : IEnumerable
{
public void Add(int i) { }
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
}
class C1 : IEnumerable<int>
{
public void Add(int i) { }
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
IEnumerator<int> IEnumerable<int>.GetEnumerator() => throw new NotImplementedException();
}
using System.Collections;
using System.Runtime.CompilerServices;
C x = [1]; // ダメ!これも C# 13 で行けるようにしそう。
C1 y = [1]; // 行ける。
[CollectionBuilder(typeof(C), "Create")]
class C
{
public static C Create(ReadOnlySpan<int> _) => new();
}
[CollectionBuilder(typeof(C1), "Create")]
class C1 : IEnumerable<int>
{
public static C1 Create(ReadOnlySpan<int> _) => new();
IEnumerator<int> IEnumerable<int>.GetEnumerator() => throw new NotImplementedException();
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
}
using System.Collections;
C x = new C { 1, "2" }; // これ行けるでしょ。
C y = [1, "2"]; // これが行けない理由ないでしょ。
class C : IEnumerable // IEnumerable<object> でもダメ。
{
public void Add(int x) { }
public void Add(string x) { }
IEnumerator IEnumerable.GetEnumerator() => throw new NotImplementedException();
}
当時の C# 1.0 はもう帰ってこない。
class Program
{
public static void Main()
{
int M = 1;
int C = 1;
int D = 1;
N(M<C, D>(1)); // LangVersion 1 でもコンパイル通らない。
}
static void N(bool x, bool y);
}
配信URL: https://www.youtube.com/watch?v=PhlJKjUCARA
https://devblogs.microsoft.com/visualstudio/visual-studio-2022-17-9-now-available/ https://devblogs.microsoft.com/dotnet/our-vision-for-dotnet-9/
core 9167 core 9176 https://github.com/dotnet/core/blob/main/release-notes/9.0/preview/preview1/libraries.md
Preview 版の告知はブログ少な目にして、GitHub discussion でやりたいって。 (ここでリンク書いちゃうと mentioned 通知が行っちゃうのが嫌…)
announcements 293
CountBy, AggregateBy, Index 辺り。Index はだいぶうれしい。 JSON のインデント文字指定
C# に新規実装はほぼなし。 see https://github.com/ufcpp-live/UfcppLiveAgenda/issues/85
IDE What’s New ページに Copilot が並んでるけど、VS 組み込みになった?(要調査) new Visual Studio setting experience