If your struct has defined implicit conversion from string, then null keyword will be implicitly handled as string and there will be no compiler error.
To prevent this you could define second implicit conversion from any other reference type. Then implicit casting from null keyword becomes ambiguous and will produce error:
Exactly what we wanted.
To prevent this you could define second implicit conversion from any other reference type. Then implicit casting from null keyword becomes ambiguous and will produce error:
Argument type 'null' is not assignable to parameter type 'MyType'
Exactly what we wanted.
Комментариев нет:
Отправить комментарий