Pho*_*ian 2 c# c#-3.0 c#-2.0 c#-4.0
class CoOrds
{
public int x, y;
public CoOrds() {
x = 0;
y = 0;
}
public CoOrds(int x, int y) {
this.x = x;
this.y = y;
}
}
public CoOrds toto() {
CoOrds B = new CoOrds(3, 2);
return B;
}
private void result_Click(object sender, EventArgs e) {
l6.Text = "";
CoOrds D = new CoOrds();
D = toto();
l6.Text = "(" + D.x + "," + D.y + ")";
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
Error 2 Inconsistent accessibility: return type 'johny.Form1.CoOrds' is less accessible than method 'johny.Form1.toto()
由于您的CoOrds类嵌套在其中Form1,因此默认情况下private(即仅在Form1类中使用).最简单的解决方案就是CoOrds上课public.
public class CoOrds{
public int x, y; // ...
Run Code Online (Sandbox Code Playgroud)
另一种选择是简单地取消嵌套CoOrds类,即Form1完全将类的声明移到类之外.
| 归档时间: |
|
| 查看次数: |
2168 次 |
| 最近记录: |