Declaring classes
class A
{
public string a;
public static implicit operator A(B b) => new A() { a = b.b };
}
class B
{
public string b;
}
comparison ?:
and if-else
static public A Method1(B b)
{
return (b is null) ? null : b; //equally return b;
}
static public A Method2(B b)
{
if (b is null) return null; else return b;
}
Method1 will throw an exception
Method2 will work fine
Method1(null);
Method2(null);
Why do they behave differently?