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

質問編集履歴

2

修正

2015/10/26 10:06

投稿

fender0131
fender0131

スコア121

title CHANGED
File without changes
body CHANGED
@@ -50,4 +50,68 @@
50
50
  sum = a1 + b1 + c1 + d1 + e1 + f1 + g1 /* ・・・ + z1 */;
51
51
  }
52
52
  }
53
+ }
54
+
55
+
56
+ ※ 追記1
57
+
58
+ 試行錯誤した結果、クラスを引数として渡せたと思うのですが、この方法はあっていますでしょうか?
59
+ 他に最適な方法などありますでしょうか?
60
+ お手数おかけして申し訳ございませんが、再度ご教授願えませんでしょうか?
61
+
62
+
63
+ using System;
64
+ using System.Collections.Generic;
65
+ using System.ComponentModel;
66
+ using System.Data;
67
+ using System.Drawing;
68
+ using System.Linq;
69
+ using System.Text;
70
+ using System.Threading.Tasks;
71
+ using System.Windows.Forms;
72
+
73
+ namespace WindowsFormsApplication4
74
+ {
75
+ class hensuu
76
+ {
77
+ public double sum;
78
+
79
+ public double a1;
80
+ public int b1;
81
+ public int c1;
82
+ public int d1;
83
+ public int e1;
84
+ public int f1;
85
+ public double g1;
86
+ // ... int z = 26
87
+ }
88
+
89
+ public partial class Form1 : Form
90
+ {
91
+ public Form1()
92
+ {
93
+ InitializeComponent();
94
+ }
95
+
96
+ public void Form1_Load(object sender, EventArgs e)
97
+ {
98
+ hensuu h = new hensuu();
99
+
100
+ h.a1 = 1.5;
101
+ h.b1 = 2;
102
+ h.c1 = 3;
103
+ h.d1 = 4;
104
+ h.e1 = 5;
105
+ h.f1 = 6;
106
+ h.g1 = 7.5;
107
+
108
+ math(ref h);
109
+
110
+ }
111
+
112
+ private void math (ref hensuu h)
113
+ {
114
+ h.sum = h.a1 + h.b1 + h.c1 + h.d1 + h.e1 + h.f1 + h.g1 /* ・・・ + z1 */;
115
+ }
116
+ }
53
117
  }

1

修正

2015/10/26 10:06

投稿

fender0131
fender0131

スコア121

title CHANGED
File without changes
body CHANGED
@@ -30,22 +30,22 @@
30
30
  private void Form1_Load(object sender, EventArgs e)
31
31
  {
32
32
 
33
+ double sum = 0;
34
+
33
- int a1 = 1;
35
+ float a1 = 1.5;
34
36
  int b1 = 2;
35
37
  int c1 = 3;
36
38
  int d1 = 4;
37
39
  int e1 = 5;
38
40
  int f1 = 6;
39
- int g1 = 7;
41
+ float g1 = 7.5;
40
42
  // ... int z = 26
41
43
 
42
- int sum = 0;
43
-
44
44
  math(ref sum, a1, b1, c1,d1,e1,f1,g1 /* ... z */);
45
45
 
46
46
  }
47
47
 
48
- private void math (ref int sum, int a1, int b1, int c1, int d1, int e1, int f1, int g1 /* ... int z */)
48
+ private void math (ref double sum, float a1, int b1, int c1, int d1, int e1, int f1, float g1 /* ... int z */)
49
49
  {
50
50
  sum = a1 + b1 + c1 + d1 + e1 + f1 + g1 /* ・・・ + z1 */;
51
51
  }