fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. class Program
  5. {
  6. static void Main(string[] args)
  7. {
  8. var testItems = new List<TestItem>();
  9.  
  10. var t1 = new TestItem("デバイス1");
  11. t1.AddMeasured(new Measured("電圧", "V", 1));
  12. t1.AddMeasured(new Measured("電流", "mA", 100));
  13. testItems.Add(t1);
  14.  
  15. var t2 = new TestItem("デバイス2");
  16. t2.AddMeasured(new Measured("電圧", "V", 2));
  17. t2.AddMeasured(new Measured("電流", "mA", 200));
  18. testItems.Add(t2);
  19.  
  20. var t3 = new TestItem("デバイス3");
  21. t3.AddMeasured(new Measured("電圧", "V", 3));
  22. t3.AddMeasured(new Measured("電流", "mA", 300));
  23. testItems.Add(t3);
  24.  
  25. foreach (var item in testItems)
  26. {
  27. item.Print();
  28. }
  29. }
  30. }
  31.  
  32. public class Measured
  33. {
  34. public Measured(string name, string unit, double value)
  35. {
  36. this.Name = name; this.Unit = unit; this.Value = value;
  37. }
  38.  
  39. public string Name { get; set; }
  40. public string Unit { get; set; }
  41. public double Value { get; set; }
  42.  
  43. public override string ToString()
  44. {
  45. return string.Format("{0}: {1}{2}", Name, Value, Unit);
  46. }
  47. }
  48.  
  49. public class TestItem
  50. {
  51. private List<Measured> _MeasuredList = new List<Measured>();
  52.  
  53. public string Name { get; set; }
  54. public List<Measured> MeasuredList => _MeasuredList;
  55.  
  56. public TestItem(string name)
  57. {
  58. this.Name = name;
  59. }
  60.  
  61. public void AddMeasured(Measured m)
  62. {
  63. MeasuredList.Add(m);
  64. }
  65.  
  66. public void Print()
  67. {
  68. Console.WriteLine("[{0}]", Name);
  69. foreach (var m in MeasuredList)
  70. {
  71. Console.WriteLine("\t{0}", m);
  72. }
  73. }
  74. }
Success #stdin #stdout 0.01s 29664KB
stdin
Standard input is empty
stdout
[デバイス1]
	電圧: 1V
	電流: 100mA
[デバイス2]
	電圧: 2V
	電流: 200mA
[デバイス3]
	電圧: 3V
	電流: 300mA