T
T
Troodi Larson2018-08-26 22:24:06
C++ / C#
Troodi Larson, 2018-08-26 22:24:06

Setting a variable to be an object?

Example:

var tmp;
if(true or false){
  tmp = new FirefoxDriver();
} else {
  tmp = new ChromeDriver();
}

That is, the object can be anything.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
GavriKos, 2018-08-26
@troodi

To tell you the data type, or what? The simplest is Object. The most correct is the base type for both Drivers that inherit from it.

J
justslipknot, 2018-08-27
@justslipknot

IMHO, it will be more correct to use interfaces

IDriver driver;
if (true or false)
{
    driver = new FirefoxDriver();
}
else
{
    driver = new ChromeDriver();
}

ChromeDriver and FirefoxDriver in turn inherit from the IDriver interface and implement its methods/properties

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question