C++中:
struct Point3D
{
float x,y,z;
}struct Line3D
{
Point3D pt1;
Point3D pt2;
}bool RayIntersectSurf(const Line3D&ray)
{
   float A = ray.pt1.x*ray.pt2.y;
}
C#中:
class Point3D
{
float x,y,z;
}class Line3D
{
Point3D pt1 = new Point3D();
Point3D pt2 = new Point3D();
}上面的写法错了吗?我想在 class Line3D 里面定义两个 Point3D 类型的成员变量,然后通过new一个Line3D对象ray,可以通过ray.pt1.x这样方式确定一条直线。在C#中应该如何实现?即在另一个C#类中如何把下面的C++代码
bool RayIntersectSurf(const Line3D&ray)
{
   float A = ray.pt1.x*ray.pt2.y;
}
转为C#代码来实现?

解决方案 »

  1.   

    举个例子吧:using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Media.Media3D;
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                Line3D ray = new Line3D();
            }
            bool RayIntersectSurf(Line3D ray)
            {
                float A = (float)(ray.pt1.X * ray.pt2.Y);
                return true;
            }
        }
        class Line3D
        {
            public Point3D pt1 = new Point3D();
            public Point3D pt2 = new Point3D();
        }
    }
      

  2.   

    这个方法可以,同时,C#中也有结构体,你可以直接用结构体的方法,代码如下(已经调试过了):
    class ProgramA
        {
            public struct Point3D
            {
               public float x, y, z;
            }
            struct Line3D
            {
               public  Point3D pt1;
               public  Point3D pt2;        }
            bool RayIntersectSurf(Line3D ray)
            {
                ray = new Line3D();
                float A = ray.pt1.x * ray.pt2.y;        }
            
        }
      

  3.   

    原来只要在前面加个Public啊~~谢谢