Get distance from all objects in an Collider[] and compare

I have been using

stockpile =Physics.OverlapSphere(transform.position,Mathf.Infinity,stockpileLayer);

to get an array of colliders hit, in a layermask. This completely works but how would I get the distance in each and store them.

So you have an array of Colliders and your looking for the distance to each of these objects. (I’m guessing from the current transform you are working with)

Maybe something like this:

foreach( Collider collide in stockpile ){
    float _dist = Vector3.Distance(transform.position,

    distanceList.Add( _dist );

Distance List being a list of floats to carry each of the distances from the current transform to each of the colliders in stockpile.