Oh!Super164 取り留めのない日記のような

2025/9/7 日曜日

いつの間に?

Filed under: c# — pecos @ 22:45:37

知らない間に便利になってたC#構文

void foo(object a) {
  //今までこんな感じだったのが
    var t = a as T;
    if (t is not null) {
        t.bar();
    }
    //これで済む
    if (a is T t) {
        t.bar();
    }
}

これが思いの外便利。
他にもTupleに名前付けられたりとかVSCodeの構文チェッカーがいろいろ指南してくれる。

コメントはまだありません »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress