回答編集履歴

1

「c」を見つけたら要素を

2016/07/21 12:15

投稿

hidetzu
hidetzu

スコア19

test CHANGED
@@ -8,12 +8,32 @@
8
8
 
9
9
  new List<string>() { "b" },
10
10
 
11
- new List<string>() { "c", "C01" },
11
+ new List<string>() { "c" },
12
12
 
13
13
  new List<string>() { "d" }
14
14
 
15
15
  };
16
16
 
17
+
18
+
19
+ var result = list.Select(item =>
20
+
21
+ {
22
+
23
+ if (item.Contains("c"))
24
+
25
+ {
26
+
27
+ var new_list = new List<string>(item);
28
+
29
+ new_list.Add("C01");
30
+
31
+ return new_list;
32
+
33
+ }
34
+
35
+ return item;
36
+
37
+ })
38
+
17
39
  ```
18
-
19
- コレクション初期化子でこんな感じでどうでしょうか。