Scale object to certain length

How make object scale to match exact length of its bounds property ?

For example, I need myobject.GetComponent().bounds.size.z to make equal of 5.0f, how can I reach it?

Thank you in advance.

Something like this could work:

float targetSize = 5;
float currentSize = myobject.GetComponent().bounds.size.z; // I'm not sure if this compiles (I guess you need to specify the component type)

Vector3 scale = myobject.trasform.localScale;

scale.z = targetSize * scale.z / currentSize;

myobject.trasform.localScale = scale;