Closed ufcpp closed 2 years ago
配信なかった間に、配信中に口頭でだけ話したけど文章で残してなかったものを色々ブログ化してたけども…
まだまだネタが残ってたり
new[] {1} [0..][0..][0..] is [..[..[1]]]
new int[] {} [..][..][..] is [..[..[]]]
// Visual Studio はこれを怒らない。
// Resharper は double negation 直すか?って聞いてくるらしい。
if (x is not not not not not not not not not not not null)
{
Console.WriteLine("x is not null");
}
多分バグ。 要バグ報告。
new[] { 1 } is [var x] and x is 1
using System.Text;
var utf8 = Encoding.UTF8.GetBytes("何か").AsSpan();
// BOM を取る
if (utf8 is [0xEF, 0xBB, 0xBF, .. var noBom])
{
utf8 = noBom;
}
m(new byte[] { 1, 2, 3, 4 });
void m(Span<byte> span)
{
if (span is [var head, .. var tail])
{
Console.WriteLine(head);
m(tail);
}
}
辞書パターンも出るの? (案だけあって、進捗なし)
// 案はあるけど、リストパターン以上に需要低そう…
// ただ、文法的にはよっぽど素直な予感あり。
var d = new Dictionary<string, string>()
{
["abc"] = "one",
};
if (d is { ["abc"] is "one"})
{
}
var d = new Dictionary<string, string>()
{
{ "abc", "one" },
};
// リストパターンが enumerable 対応するならこう書ける?
if (d is [ .., ("abc", "one"), ..])
{
}
多分仕様的にダメなんだけど、せめてエラーメッセージもうちょっとまともにしてほしい事案。
var x = new[,] { { 1, 2 }, { 3, 4 } };
var y = x[^1, ^1]; // これ、元からダメ。
if(x is [[1,..], [_,_]]) // なのでこれもダメな可能性大。
{
}
// rectangular array は元から変。
// 最適化もかかりにくくてあんまり使えない。
var x = new[,] { { 1, 2 }, { 3, 4 } };
Console.WriteLine(x is System.Collections.IEnumerable);
Console.WriteLine(x is IEnumerable<int>);
foreach (var item in x) // パターンベース foreach
{
Console.WriteLine(item);
}
↑特別な人でした。
var s = $"{123:X}"; // 条件演算子の : と書式指定の : の区別がつかない
void m(object x)
{
var s = @$"{( // なのでここ、 () が必須。
x is int i
? i
: "aaa"
)}";
}
// C# 10 で improved interpolated string が入ったので、
// {} にいろいろ詰め込むのはメリットなくはない(速い可能性はある)。
// とはいえ、メソッド抽出しろよ。
var s = @$"{( // なのでここ、 () が必須。
x is int[] a && a is [var i, ..]
? i
: "aaa"
)}";
// 多分これ書ける interpolated string handler 書けるはず。
// (せめて key: value であったほしいけど無理w)
var s = CreateDictionary($"{x:Key1}{y:Key2}");
非匿名
匿名、アウトー-
Stack Trace Explorer の現状、だいぶ未成熟感ある… まあまだ preview 2 なので…
例外ダイアログとかに組み込まれてくれたらだいぶ嬉しそう。
「コードクリーンナップの設定がおかしい人がいたのでクリーンナップしておきました。」
成人式。
配信URL: https://youtu.be/lxr0QlZR0M4
.NET チームもそろそろホリデーから帰ってきたっぽい感じなので配信も再開(2か月ぶり)。
リリースノート
https://docs.microsoft.com/en-us/visualstudio/releases/2022/release-notes-preview#17.1.0-pre.2.0
気になるとこ:
C# 11
2個ほど実装追加。
17.1p1 から
17.1p2 から