❔ conversion operator
someone wanna explain what is the difference between implicit and explicit operator?
6 Replies
Console.WriteLine(7)
, the int is implicitly converted to a stringnot really, thats just calls 7.ToString() in the inside
implicit is basically when the compiler casts for you without writing the cast
eg
that can be limited with some types, u can explicitly cast a type, but cannot implicitly cast it, and vice versa
This example here seems pretty straight forward https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/operators/user-defined-conversion-operators
example u can only explicitly cast a float to int, but cannot implicitly cast it
thanks
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.