i was reading this book about kinect ,
and i have face a problem in this code :
void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
SkeletonFrame frame = e.OpenSkeletonFrame();
if (frame == null)
return;
Skeleton[] skeletons ;
skeletons = frame.GetSkeletons();
if (skeletons.All(s => s.TrackingState == SkeletonTrackingState.NotTracked))
return;
}
in this section :
if (skeletons.All(s => s.TrackingState == SkeletonTrackingState.NotTracked))
i want to know who provide the value of the parameter s in the lambda exp above ?
and also what skeletons.All
mean and what it's return ?
The All
method accepts a Func<Skeleton, bool>
and a Func<Skeleton, bool>
is a delegate that encapsulates a method that accepts a Skeleton
parameter and returns a bool
.
You could define such a method yourself:
private bool YourMethod(Skeleton s)
{
return s.TrackingState == SkeletonTrackingState.NotTracked
}
...and pass this one to the All
method:
if (skeletons.All(YourMethod))
YourMethod
will be called for each Skeleton
in skeletons
and the All
method will return true
if YourMethod
returns true
for all those Skeleton
objects.
s => s.TrackingState == SkeletonTrackingState.NotTracked
is an anonymous version of YourMethod
: https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/statements-expressions-operators/anonymous-methods