none
'foreach' keyword cannot operate on variables of type 'void' C# RRS feed

  • Question

  • Hi,

    I am working on a project to upgrade an open source project to use the .NET 4.5.2 Framework that uses the Kinect 1.8 SDK. However, I continuously receive an error of 'foreach statement cannot operate on variables of type 'void' because 'void' does not contain a public definition for 'GetEnumerator'' on the codeblock shown below:-

    foreach (Skeleton data in skeletonFrame.CopySkeletonDataTo(this._skeletonDataFrame))
                        {
                            if (SkeletonTrackingState.Tracked == data.TrackingState | SkeletonTrackingState.PositionOnly == data.TrackingState)
                            {
                                // Draw bones
                                Brush brush = brushes[iSkeleton % brushes.Length];
    
                                skeleton.Children.Add(Utility.getBodySegment(data.Joints, brush, ref _nui, ref skeleton, JointType.HipCenter, JointType.Spine, JointType.ShoulderCenter, JointType.Head));
    
                                skeleton.Children.Add(Utility.getBodySegment(data.Joints, brush, ref _nui, ref skeleton, JointType.ShoulderCenter, JointType.ShoulderLeft, JointType.ElbowLeft, JointType.WristLeft, JointType.HandLeft));
    
                                skeleton.Children.Add(Utility.getBodySegment(data.Joints, brush, ref _nui, ref skeleton, JointType.ShoulderCenter, JointType.ShoulderRight, JointType.ElbowRight, JointType.WristRight, JointType.HandRight));
    
                                skeleton.Children.Add(Utility.getBodySegment(data.Joints, brush, ref _nui, ref skeleton, JointType.HipCenter, JointType.HipLeft, JointType.KneeLeft, JointType.AnkleLeft, JointType.FootLeft));
    
                                skeleton.Children.Add(Utility.getBodySegment(data.Joints, brush, ref _nui, ref skeleton, JointType.HipCenter, JointType.HipRight, JointType.KneeRight, JointType.AnkleRight, JointType.FootRight));
    
                                // Draw joints
                                foreach (Joint joint in data.Joints)
                                {
                                    Point jointPos = Utility.getDisplayPosition(joint, ref _nui, ref skeleton);
    
                                    Line jointLine = new Line();
    
                                    jointLine.X1 = jointPos.X - 3;
    
                                    jointLine.X2 = jointLine.X1 + 6;
    
                                    jointLine.Y1 = jointLine.Y2 = jointPos.Y;
    
                                    jointLine.Stroke = jointColors[joint.JointType];
    
                                    jointLine.StrokeThickness = 6;
    
                                    skeleton.Children.Add(jointLine);
    
                                    _handler.AppendJointHistory(joint);
                                }
                            }
                        }

    I cannot understand why this is happening as the declared method is of type void.

    private void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)

    I would appreciate your help.

    Peter

    Tuesday, January 27, 2015 7:40 PM

Answers

  • What is the output of  the skeletonFrame.CopySkeletonDataTo(this._skeletonDataFrame) fmethod?  Im assuming it just returns void.  You would need to first do the CopySkeletonDataTo() and then do your foreach (Skeleton data in this._skeletonDataFrame)
    • Marked as answer by PeterWagner Wednesday, January 28, 2015 8:45 AM
    Tuesday, January 27, 2015 8:00 PM

All replies

  • What is the output of  the skeletonFrame.CopySkeletonDataTo(this._skeletonDataFrame) fmethod?  Im assuming it just returns void.  You would need to first do the CopySkeletonDataTo() and then do your foreach (Skeleton data in this._skeletonDataFrame)
    • Marked as answer by PeterWagner Wednesday, January 28, 2015 8:45 AM
    Tuesday, January 27, 2015 8:00 PM
  • Hi Kjwinkel,

    Thanks for your reply. I have tried your idea and it worked! In response to your question, according to the SDK documentation the CopySkeletonDataTo() method copies the skeleton data into an array.

    I guess the original code was poorly implemented.

    Wednesday, January 28, 2015 8:45 AM