回答編集履歴

1

見直しキャンペーン中

2023/07/22 04:40

投稿

TN8001
TN8001

スコア9862

test CHANGED
@@ -1,61 +1,31 @@
1
1
  こんなのでいいですか?
2
-
3
- ```C#
2
+ ```cs
4
-
5
3
  using System;
6
-
7
4
  using System.IO;
8
-
9
5
  using System.Linq;
10
-
11
6
  using System.Text;
12
-
13
7
  using Newtonsoft.Json;
14
8
 
15
-
16
-
17
9
  namespace CsvRead
18
-
19
10
  {
20
-
21
11
  class Test
22
-
23
12
  {
24
-
25
13
  static void Main()
26
-
27
14
  {
28
-
29
15
  var sr = new StreamReader(@"test.csv", Encoding.GetEncoding("shift_jis"));
30
-
31
16
  {
32
-
33
17
  var keys = sr.ReadLine().Split(',');
34
-
35
18
  while(!sr.EndOfStream)
36
-
37
19
  {
38
-
39
20
  var values = sr.ReadLine().Split(',');
40
-
41
21
  var dic = keys.Zip(values, (k, v) => new { k, v }).ToDictionary(x => x.k, x => x.v);
42
-
43
22
  Console.WriteLine(JsonConvert.SerializeObject(dic));
44
-
45
23
  }
46
-
47
24
  }
48
-
49
25
  }
50
-
51
26
  }
52
-
53
27
  }
54
-
55
28
  ```
56
29
 
57
-
58
-
59
30
  参考
60
-
61
31
  [.net - Map two lists into a dictionary in C# - Stack Overflow](https://stackoverflow.com/questions/4038978/map-two-lists-into-a-dictionary-in-c-sharp)