Can you use "GetComponent" dynamically?

I’m using:

public GameObject target;
private ValueField valueField;

void Awake (){
	valueField = target.GetComponent<ValueField>();

void OnMouseDown () 

It works great. I can set the target GameObject by drag and dropping it into the unity property inspector.
I was wanting to also set the “Class” or “Script” or what ever you call it in the property inspector too. so something like:

public varTargetGameObject;
public varClassName;
private varTargetInstance;

varTargetInstance = varTargetGameObject.GetComponent(varClassName);

Can you do something like that?
What’s the correct syntax?

Sure thing see the documentation here.

Note that it will return type Component, so you will have to cast it to something more useful in most cases anyway.