Clicking on an Object to Make it the Variable Target

How could i click a cube and have it because the variable target.

I would like to have this in C# so if that is possible please give it to me like that

I saw this post which is practically what i need but i got errors converting it because it was in javascript

The main problem im getting is the variable ray in that post

This is the script in that post

var hit: RaycastHit;
var ray;
private var target : Transform;

function Update () 
{
    if(Input.GetMouseButtonDown(0))    // for standalone
       {
         if (Physics.Raycast (ray, hit, 100)) 
           {
              if(hit.collider.gameObject.tag == "TagName")
                {
                 target = hit.collider.gameObject;
              }
       }
}

What type of variable is that?

This is the C# version:

RaycastHit hit;
Ray ray;
Transform target;

void Update (){
  if (Input.GetMouseButtonDown(0)){
    ray = Camera.main.ScreenPointToRay(Input.mousePosition);
    if (Physics.Raycast (ray, out hit, 100)){
      if (hit.transform.tag == "TagName"){
        target = hit.transform;
      }
    }
  }  
}