How can I assign an undefined class?

//What do I use?
********* nodeClass;

    private void ClassAssigner(GameObject gameObject, int classNumber)
    {
        switch(classNumber)
        {
            case 1: 
                 nodeClass = gameObject.AddComponent<Foo>();
                break;      
            case 2:
                nodeClass = gameObject.AddComponent<Bar>();
                break;
            default:
                break;
        }

        nodeClass.first       = Random.Range(1, 100);
        nodeClass.second      = true;
    }

in the 'nodeClass ’ I am inheriting a base class that has both first and second properties so I just need to know how to assign the undefined class ‘nodeClass’ to my game object so I can access first and second properties in the base class of ‘nodeClass’, also what is this called?

public BaseNode : Mono
{
    int first;
    bool second;
}

public Foo: BaseNode
{
  ///blah
}

public Bar: BaseNode
{
  ///blah
}

Thank you.

The term you may be thinking of is polymorphism but that is not what you are doing here.

You make use of basic inheritance (which is just find here).

Your unknown type is the parent class.

private void ClassAssigner(GameObject gameObject, int classNumber)
  {
       BaseNode nodeClass = null;    
         switch(classNumber)
         {
             case 1: 
                  nodeClass = gameObject.AddComponent<Foo>() as BaseNode;
                 break;      
             case 2:
                 nodeClass = gameObject.AddComponent<Bar>() as BaseNode;
                 break;
             default:
                 break;
         }
 
         nodeClass.first       = Random.Range(1, 100);
         nodeClass.second      = true;
     }

Your nodeClass reference can only see the member of BaseNode as it is its type. If you need to downcast, for instance to Foo, you need to perform an explicit cast:

Foo foo = (Foo)nodeClass;

// foo is a Foo reference and can access any member of Foo and public/protected of BaseNode