回答編集履歴
1
修正
answer
CHANGED
@@ -1,4 +1,52 @@
|
|
1
1
|
forの外にList<int>をdata4とdat5用に2つ作って
|
2
2
|
forを回しながらそれぞれのListに値を突っ込む。
|
3
3
|
data4とdata5のintをやめてList<int>にする。
|
4
|
-
という方法を思いつきました。
|
4
|
+
という方法を思いつきました。
|
5
|
+
```C#
|
6
|
+
using System;
|
7
|
+
using System.Collections.Generic;
|
8
|
+
|
9
|
+
namespace listtest3
|
10
|
+
{
|
11
|
+
class Program
|
12
|
+
{
|
13
|
+
public class dataModel
|
14
|
+
{
|
15
|
+
public string data1 { get; set; }
|
16
|
+
public string data2 { get; set; }
|
17
|
+
public string data3 { get; set; }
|
18
|
+
public List<int> data4 { get; set; }
|
19
|
+
public List<int> data5 { get; set; }
|
20
|
+
}
|
21
|
+
|
22
|
+
static void Main(string[] args)
|
23
|
+
{
|
24
|
+
dataModel model = new dataModel();
|
25
|
+
List<dataModel> list = new List<dataModel>();
|
26
|
+
|
27
|
+
model.data1 = "値1";
|
28
|
+
model.data1 = "値2";
|
29
|
+
model.data1 = "値3";
|
30
|
+
|
31
|
+
List<int> for_data4 = new List<int>();
|
32
|
+
List<int> for_data5 = new List<int>();
|
33
|
+
|
34
|
+
for(int i = 0; i < 10; i++)
|
35
|
+
{
|
36
|
+
for_data4.Add(i);
|
37
|
+
for_data5.Add(i * 10);
|
38
|
+
}
|
39
|
+
|
40
|
+
model.data4 = for_data4;
|
41
|
+
model.data5 = for_data5;
|
42
|
+
|
43
|
+
list.Add(model);
|
44
|
+
|
45
|
+
Console.WriteLine(string.Join(" ", list[0].data5));
|
46
|
+
|
47
|
+
Console.ReadKey();
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
|
52
|
+
```
|