I want to declare an object based on a variable value.
This is the code that I'm trying to run and that doesn't compiles:
if (bcheck == 0)
IWebDriver driver = new ChromeDriver();
else if (bcheck == 1)
IWebDriver driver = new FirefoxDriver();
else if (bcheck == 2)
IWebDriver driver = new InternetExplorerDriver();
If I try to compile the code, I get this error message:
Embedded statement cannot be a declaration or labeled statement
How can I rewrite the code?
The driver object is used in the code below and I have to keep that name in order to don't change program flow.