本文介绍了不能分配成员班的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Hellow我有3个课程我无法使用此代码分配会员x
Hellow i have 3 classes i could not assigne the member x in point class
using this code
private void FormLoad(object sender, EventArgs e)
{
MyPlate mp = new MyPlate();
mp.LP[0].P.X = 1;<-----------Error
}
class point
{
private double x, y, z;
public point() { }
public point(double xi, double yi, double zi)
{ X = xi; Y = yi; Z = zi; }
public double X { get { return x; } set { x = value; } }
public double Y { get { return y; } set { y = value; } }
public double Z { get { return z; } set { z = value; } }
}
//---------------------------------------------
class MyLine
{
private point[] p = new point[100];
public MyLine() { }
public MyLine(point[] Xp)
{
p = Xp;
allocate();
}
private void allocate()
{int i;
for(i = 0; i < 100; i++)
P[i] = new point();
//p[i] = new point();
}
public point[] P{ get { return p; } set { p = value; } }
}
//-----------------------------------------------------
class MyPlate
{
private MyLine[] lp = new MyLine[100];
private point[] p = new point[100];
public MyPlate() { }
public MyPlate(MyLine[] Xlp, point[] Xp)
{
LP = Xlp;
P = Xp;
allocate();
}
private void allocate()
{int i;
for(i=0;i<100;i++)
{
LP[i]=new MyLine();
P[i] = new point();
//lp[i] = new MyLine();
//p[i] = new point();
}
}
//---------------------------------------------------
public MyLine[] LP { get { return lp; } set { lp = value; } }
public point[] P { get { return p; } set { p = value; } }
}
推荐答案
mp.LP[0].P[0].X = 1;
如果你使用了一些更有意义的变量名,你的代码会更容易调试。
Your code would be easier to debug if you used some more meaningful variable names.
这篇关于不能分配成员班的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!