|
Thanks for the explanation. I can see how the implicit operator can be
useful in the example you describe; still, I think it wasn't necessary
for C# to expose them to us. I.e., let us deal with the explicit casts
and spare the confusion they may cause. In other words, an implicit
cast from a Pear object to a Truck object can seem quite odd, assuming
their inheritance tree has nothing in common. // David Jonathan Pryor wrote: It's good to keep this in mind: C#'s "builtin" types (int, long, etc.) are actually aliases for managed types (System.Int32, System.Int64, etc.). These managed types are (for Mono, at least) written in C#.You expect the following code to work: int n = 42; long l = n; short s = (short) n; Which means that the following code also works: System.Int32 n = 42; System.Int64 l = n; System.Int16 s = (System.Int16) n; Which means that the managed implementation of those managed types needs *some way* to represent to the compiler/runtime that some coercions are "safe" (can be done implicitly), while others are "unsafe" (can be done explicitly). C#'s implicit/explicit operators are how this is declared and defined. As for the differences between implicit & explicit, you understand the difference already. Implicit == doesn't need a cast; explicit == requires a cast. - Jon On Thu, 2003-10-16 at 16:52, David La Motta wrote: |
- [Mono-list] implicit, explicit, and why does C# have thes... David La Motta
- Re: [Mono-list] implicit, explicit, and why does C# ... Jonathan Pryor
- RE: [Mono-list] implicit, explicit, and why does... David La Motta
- RE: [Mono-list] implicit, explicit, and why ... Todd Berman
- Re: [Mono-list] implicit, explicit, and ... David La Motta
- RE: [Mono-list] implicit, explicit, and why ... Arild Fines
- Re: [Mono-list] implicit, explicit, and ... David La Motta
- RE: [Mono-list] implicit, explicit,... Todd Berman
- RE: [Mono-list] implicit, explicit,... Arild Fines
- RE: [Mono-list] implicit, explicit, and why does C# ... Luciano Callero
- RE: [Mono-list] implicit, explicit, and why does C# ... Kenneth Brubaker
