how to create an array of gameobjects by using raycast?

Hi, how can I use raycast to create an array of gameobjects to access later on? Something like this-

using UnityEngine;
using System.Collections;

public class transformation : MonoBehaviour {
public LayerMask touchinputmask;
public GameObject [] objects;
	void Start () {
	
	}
	

	void Update () {
		Ray r = new Ray(transform.position,Vector3.Up,100,touchinputmask);
		RaycastHit[] hits = Physics.RaycastAll(r,100,touchinputmask);

		foreach(RaycastHit hit in hits)
		{
             objects=hit.collider.tag;

		}
	}
}

Untested, but you should get the idea:

using UnityEngine;
using System.Collections;
 
public class transformation : MonoBehaviour
{
  public LayerMask touchinputmask;
  public GameObject [] objects;

  void Update ()
  {
    RaycastHit[] hits = Physics.RaycastAll(transform.position, Vector3.up, 100.0f, touchinputmask);
    if( hits.Length > 0 )
    {
      objects = new GameObject[ hits.Length ];
      for( int i=0; i<hits.Length; i++ )
      {
        objects _= hits*.collider.gameObject;*_

}
}
}
}