C
C#7mo ago
cypherpotato

✅ Difference between explicit and implicit operators

Hello there. What's the difference between defining an implicit and explicit operator? I would like to know the difference between
public static implicit operator JsonValue(JsonArray jarray) => jarray.AsJsonValue();
public static implicit operator JsonValue(JsonArray jarray) => jarray.AsJsonValue();
And
public static explicit operator JsonValue(JsonArray jarray) => jarray.AsJsonValue();
public static explicit operator JsonValue(JsonArray jarray) => jarray.AsJsonValue();
8 Replies
Angius
Angius7mo ago
It's in the docs
Jimmacle
Jimmacle7mo ago
basically, whether it happens implicitly or explicitly
Angius
Angius7mo ago
But tl;dr would be
var n = new MyNumber();
int a = n; // implicit
int b = (int)n; // explicit
var n = new MyNumber();
int a = n; // implicit
int b = (int)n; // explicit
cypherpotato
cypherpotatoOP7mo ago
oh, I see. explicit operators requires the casting syntax
Angius
Angius7mo ago
Assuming MyNumber has cast operators to int
cypherpotato
cypherpotatoOP7mo ago
thank you
viceroypenguin
viceroypenguin7mo ago
don't forget to $close
MODiX
MODiX7mo ago
If you have no further questions, please use /close to mark the forum thread as answered
Want results from more Discord servers?
Add your server