Alex Rivera | Logout

implicit operator

Asked 2009-03-01T00:21:48.493
23

I just saw it was using in one of the recent answers:

public static implicit operator bool(Savepoint sp)
{
    return sp != null;
}

Why do we need word implicit here, and what does it mean?

Edit
Report

1 Answer

9

That looks like misuse of an implicit operator. I don't know what the Savepoint class does, but converting it to a boolean does not seem logical. The implicit operator enables you to check if a Savepoint reference is null or not by simply evaluating the reference:

if (point) {

instead of:

if (point != null) {

If it's used that way, that is hiding what the code is actually doing, and that goes against pretty much everything that C# is about.

answered 2009-03-01T01:38:36.267

Your Answer