Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 并非所有代码路径都返回c中的值#_C#_Kinect - Fatal编程技术网

C# 并非所有代码路径都返回c中的值#

C# 并非所有代码路径都返回c中的值#,c#,kinect,C#,Kinect,我试图在c#中为kinect编写clap程序,但GetJointDistance方法出现错误“并非所有代码路径都返回值” 这是我的方法您编写的方法应该返回一个浮点值: private float GetJointDistance 但是,您的方法主体没有任何返回语句-因此,不仅所有代码路径都不返回值,nonedo 您应该通过添加退货来解决此问题: private float GetJointDistance(Joint handR, Joint handL) { Skeleton s =

我试图在c#中为kinect编写clap程序,但GetJointDistance方法出现错误“并非所有代码路径都返回值”
这是我的方法

您编写的方法应该返回一个
浮点值

private float GetJointDistance
但是,您的方法主体没有任何
返回
语句-因此,不仅所有代码路径都不返回值,nonedo

您应该通过添加退货来解决此问题:

private float GetJointDistance(Joint handR, Joint handL)
{
    Skeleton s = new Skeleton(); 
    Joint handRight = s.Joints[JointType.HandRight];
    Joint handLeft = s.Joints[JointType.HandLeft]; 
    if (handRight.TrackingState == JointTrackingState.Tracked &&
    handLeft.TrackingState == JointTrackingState.Tracked)
    {
        this.GetJointDistance(handRight, handLeft);
    }

    return xyz;     // xyz must be a float

}
请注意,如果您的
if
语句意味着您需要返回其他内容,则需要在
if
语句中再返回一次
return
。尽管此时很可能会溢出堆栈,这取决于跟踪状态的频率

或者,让您的方法返回
void
,因为您目前似乎不需要返回:

private void GetJointDistance

应该返回
float
的方法中没有一条
return
语句。错误消息非常清楚。你读过里面的字了吗?(虽然可能更好:“无代码路径返回值”会更具体。)越过“错误”这个词并阅读实际的消息本身是非常重要的——消息有意义,而且通常非常清楚。