get height of point in NavMesh

I have a c# application with a NavMesh.
Now i to place all objects of a specific type at the NavMesh height for this position.
How can i Detect the height of a specific position on NavMesh?

I assume the NavMesh.SamplePosition() function is the right way to use it. But currently my check never gets true.
Vector3 positionToCheck = gameObject.transform.position;
if (NavMesh.SamplePosition(positionToCheck, out navMeshHit, 2, 0))
{
gameObject.transform.position = navMeshHit.position;
}
Is there something i miss?

You have the right approach (using SamplePosition) but passing an area mask of 0 will result in you never hitting anything. Try another value such as NavMesh.AllAreas.