回答編集履歴

3

リンクを追加

2022/04/27 20:19

投稿

jhashimoto
jhashimoto

スコア838

test CHANGED
@@ -7,3 +7,4 @@
7
7
  ```
8
8
  if (data.Keys.Any(key => key == s)) {
9
9
  ```
10
+ [Enumerable.Any メソッド (System.Linq) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.linq.enumerable.any?view=net-6.0)

2

表現を修正

2022/04/27 20:17

投稿

jhashimoto
jhashimoto

スコア838

test CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [Dictionary<TKey,TValue>.ContainsKey(TKey) メソッド (System.Collections.Generic) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.collections.generic.dictionary-2.containskey?view=net-6.0)
4
4
 
5
- LINQを使うと次のように書けますが、ContainsKeyを利用した方が明示的で他人が理解しやすいと思います。
5
+ `data.Keys`を使うならLINQ次のように書けますが、ContainsKeyを利用した方が明示的で他人が理解しやすいと思います。
6
6
 
7
7
  ```
8
8
  if (data.Keys.Any(key => key == s)) {

1

追記

2022/04/27 20:15

投稿

jhashimoto
jhashimoto

スコア838

test CHANGED
@@ -1,3 +1,9 @@
1
1
  キーがDictionaryに存在するかを判定するには、`ContainsKey`メソッドが使えます。
2
2
 
3
3
  [Dictionary<TKey,TValue>.ContainsKey(TKey) メソッド (System.Collections.Generic) | Microsoft Docs](https://docs.microsoft.com/ja-jp/dotnet/api/system.collections.generic.dictionary-2.containskey?view=net-6.0)
4
+
5
+ LINQを使うと次のように書けますが、ContainsKeyを利用した方が明示的で他人が理解しやすいと思います。
6
+
7
+ ```
8
+ if (data.Keys.Any(key => key == s)) {
9
+ ```