teratail header banner
teratail header banner
質問するログイン新規登録

回答編集履歴

3

リンクを追加

2022/04/27 20:19

投稿

jhashimoto
jhashimoto

スコア843

answer CHANGED
@@ -6,4 +6,5 @@
6
6
 
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

スコア843

answer 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

スコア843

answer CHANGED
@@ -1,3 +1,9 @@
1
1
  キーがDictionaryに存在するかを判定するには、`ContainsKey`メソッドが使えます。
2
2
 
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)
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
+ ```