Skip to content

Instantly share code, notes, and snippets.

@max747
Last active February 25, 2021 11:45
Show Gist options
  • Save max747/d60d93e2fa3d27c0dca17749a60f55eb to your computer and use it in GitHub Desktop.
Save max747/d60d93e2fa3d27c0dca17749a60f55eb to your computer and use it in GitHub Desktop.
C# のメモ

C# のメモ

C# のコードを読む機会があったので、調べたことを記録しておく。

前提

MS の日本語ドキュメントは機械翻訳なので時々意味不明。英語で読んだ方がいいかも?

Foo?

null 許容参照型。あるいは null 許容値型。

演算子

??

null 合体演算子。a ?? banull の場合に限り b が評価される。

https://docs.microsoft.com/ja-jp/dotnet/csharp/language-reference/operators/null-coalescing-operator

関数・メソッド

Dictionary.TryGetValue

辞書 Dictionary のメソッド。キーの存在チェックと値の取得を一挙に行う。 dict.TryGetValue(key, out var value) でキーが存在すれば true が返され、かつ引数の value に取得した値が入る。キーが存在しなければ false が返される。

https://docs.microsoft.com/ja-jp/dotnet/api/system.collections.generic.dictionary-2.trygetvalue?view=net-5.0

LINQ

統合言語クエリ。コレクション操作メソッドの集合体。SQL の構文に似せたメソッド群からなるが、SQL と直接関係があるわけではない。 関数型言語のコレクション操作をイメージするとよさそう。 遅延評価であり ToList()ToArray() などのアウトプットを要求するメソッドを呼ばない限りクエリは評価されない。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment