views:

31

answers:

3

Hi All,

Let's assume we have an array named "points" having the type of Point3D in a struct and want to use these points in a method. How to transfer from the struct to the method ? The following are from the code snippet.

Regards

Cemil

public MeshGeometry3D GetMesh3D()

{

**(just here, we want to use the 3D points coming from the GetVortices method.)**

}

public Point3D[] GetVortices()

{

      points[0] = new Point3D(1,1,1);

.

      points[100] = new Point3D(3,1,5);

}

.

.
A: 

The context of your problem is not clear. To what classes do these methods belong (if any), and by the way, what language? Who's calling the GetMesh3D method?

In short, though, why not just pass it in?

GetMesh3D( points );

Of course, this would require rewriting the method signature, which I assume you're free to do.

harpo
+1  A: 

Use a return statement in GetVortices(), and call that method from GetMesh3D().

public MeshGeometry3D GetMesh3D()
{
    Point3D[] points = GetVortices();
}
public Point3D[] GetVortices()
{
      // Declare points as an array of Point3D
      points[0] = new Point3D(1,1,1);
      // ...
      points[100] = new Point3D(3,1,5);
      return points;
}
Tomas Lycken
A: 

I assume that GetVorticies() returns the points array at the end (return points;) Then all you would have to do in GetMesh3D would be ...

public MeshGeometry3D GetMesh3D()
{
  Point3D[] points = GetVorticies();
  Point3D   somePoint = points[0];

  // make meshgeometry3d out of points and return;
}
JP Alioto