Click here to Skip to main content
15,894,405 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hellow i have 3 classes i could not assigne the member x in point class
using this code
C#
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; } }
}
Posted
Updated 18-Oct-14 6:05am
v2

The variable P in class MyLine is declared as an array, but you have not used an index to it. It should be something like:
C#
mp.LP[0].P[0].X = 1;

Your code would be easier to debug if you used some more meaningful variable names.
 
Share this answer
 
That's because "MyLine.P" isn't a point - it's an array of points.
You need to select the array element, just as you did with the MyLine array LP
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900