I am learning about conditional operators. The documentation mentions
condition ? consequent : alternative
From my example, Test1() is the current method that works, but I wanted to write the equivalent using conditional operators shown in Test2().
public void Test1(bool isTrue)
{
if (isTrue)
{
MethodA();
}
else
{
MethodB();
}
}
public void Test2(bool isTrue)
{
isTrue ? MethodA() : MethodB();
}
public void MethodA()
{
//Do This
}
public void MethodB()
{
//Do That
}
I am receiving an error for Test2()
"isTrue" is a variable but used like a type
and
Local Function 'MethodA()' must declare a body because it is not marked 'static extern'
Can someone explain why this is the case?