2015-04-20 16 views
-1

我想知道如何從一個類發送一個double值到另一個類。我正在使用Kinect,當我的公共課程主要計算雙「距離」時,如果我關閉了手,我希望將該信息發送給我的其他公共類Monitor。顯示的例子將非常感謝,因爲我是C#編程初學者。在C#中發送一個類到另一個類的雙重值

private void DrawHand(HandState handState, Point handPosition, DrawingContext drawingContext) 
    { 
     switch (handState) 
     { 
      case HandState.Closed: 
       drawingContext.DrawEllipse(this.handClosedBrush, null, handPosition, HandSize, HandSize); 
       // Distance calculation 
       foreach (var body in bodies) 
       { 
        // Get the positions 
        pRH = body.Joints[JointType.HandRight]; 
        pLH = body.Joints[JointType.HandLeft]; // pLH gets to be "home" position in the meanwhile 
        //Some maths 
        double sqDistance = Math.Pow(pRH.Position.X - pLH.Position.X, 2) + 
         Math.Pow(pRH.Position.Y - pLH.Position.Y, 2) + 
         Math.Pow(pRH.Position.Z - pLH.Position.Z, 2); 


        // This is the information I want to send to public class Monitor 
        double distance = Math.Sqrt(sqDistance); 

       } 
       break; 
     } 
    } 
+0

請填寫你的問題更清楚 – Shrivallabh

回答

0

你可以把你的距離變監測在許多方面

1類構造函數

2.屬性

3.方法

private void DrawHand(HandState handState, Point handPosition, DrawingContext drawingContext) 
    { 
     switch (handState) 
     { 
      case HandState.Closed: 
       drawingContext.DrawEllipse(this.handClosedBrush, null, handPosition, HandSize, HandSize); 
       // Distance calculation 
       foreach (var body in bodies) 
       { 
        // Get the positions 
        pRH = body.Joints[JointType.HandRight]; 
        pLH = body.Joints[JointType.HandLeft]; // pLH gets to be "home" position in the meanwhile 
        //Some maths 
        double sqDistance = Math.Pow(pRH.Position.X - pLH.Position.X, 2) + 
         Math.Pow(pRH.Position.Y - pLH.Position.Y, 2) + 
         Math.Pow(pRH.Position.Z - pLH.Position.Z, 2); 


        // This is the information I want to send to public class Monitor 
        double distance = Math.Sqrt(sqDistance); 
        // Create object of Monitor class and pass the distance 
        Moniotr obj = new Monitor(distance); 
        // using Method 
        Moniotr obj = new Monitor(); 
        obj.setDistance(distance); 
        // using public property 
        Moniotr obj = new Monitor(); 
        obj.Distance = distance; 
       } 
       break; 
     } 
    } 

這裏是樣品監測類有構造方法

public class Monitor 
{ 
    public Monitor(double distance) 
    { 
    } 
} 

這裏是樣品監測類中使用方法的方法

public class Monitor 
    { 
     public void setDistance(double distance) 
     { 

     } 
    } 

這裏與物業的做法樣品Monitor類

public class Monitor 
{ 
    private double _distance; 
    public Distance 
    { 
    get{return _distance;} 
    set{_distance=value;} 
    } 
} 
0

我不能確定你想要達到的,但是你可以通過

return value; 

這是通過調用類收到

double temp = method(); 

如果你試圖返回值將值double發送給一個類,那麼你應該使用一個參數。

例如: -

Monitor monitor1 = new Monitor(distance); 

Monitor monitor1 = new Monitor(); 
monitor1.setDistance(distance); 
+0

除非Monitor是一個靜態類,在這種情況下它應該是Monitor.setDistance(distanc E)。 –

0

我不知道我理解你的問題是這樣的,你想要什麼

public class Monitor 
     {  
public Monitor(double distance)//Constructor with double as parameter 
      { 

      } 
     } 

當你實例化該類

Monitor mo=new Monitor(distance); 
相關問題