C
C#8mo 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
Angius8mo ago
It's in the docs
Jimmacle
Jimmacle8mo ago
basically, whether it happens implicitly or explicitly
Angius
Angius8mo 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
cypherpotatoOP8mo ago
oh, I see. explicit operators requires the casting syntax
Angius
Angius8mo ago
Assuming MyNumber has cast operators to int
cypherpotato
cypherpotatoOP8mo ago
thank you
viceroypenguin
viceroypenguin8mo ago
don't forget to $close
MODiX
MODiX8mo 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