[Mono-list] implicit, explicit, and why does C# have these?
David La Motta
dlamotta@email.com
Fri, 17 Oct 2003 09:56:08 -0400
This is a multi-part message in MIME format.
--------------070101010801090009040807
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
I guess I should expand on my [sort-of] gripe. Implicit casting by the
language itself is OK where it makes sense, like in your example of int
and long. But, logically, it can be confusing to use an implicit
operator to convert between objects that have nothing in common, and
never will (like Truck and Pear, for instance).
// David
Arild Fines wrote:
>David La Motta wrote:
>
>
>>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.
>>
>>
>
>Sure, but would you really want to be required to use an explicit cast when
>converting an int to a long?
>
>
>--
>Arild
>
>AnkhSVN: http://ankhsvn.tigris.org
>Blog: http://ankhsvn.com/blog
>RSS: http://ankhsvn.com/blog/Rss.aspx
>
>King Crimson lives in different bodies at different times and the
>particular form which the group takes changes. When music appears,
>which only King Crimson can play then, sooner or later, King Crimson
>appears to play the music
>
>
>
--------------070101010801090009040807
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=ISO-8859-1">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
I guess I should expand on my [sort-of] gripe. Implicit casting by the
language itself is OK where it makes sense, like in your example of int
and long. But, logically, it can be confusing to use an implicit
operator to convert between objects that have nothing in common, and
never will (like Truck and Pear, for instance).<br>
<br>
// David<br>
<br>
<br>
Arild Fines wrote:<br>
<blockquote type="cite"
cite="midAJEELJINGEGOMNJPJFKKCEIEDCAA.arild.fines@broadpark.no">
<pre wrap="">David La Motta wrote:
</pre>
<blockquote type="cite">
<pre wrap="">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.
</pre>
</blockquote>
<pre wrap=""><!---->
Sure, but would you really want to be required to use an explicit cast when
converting an int to a long?
--
Arild
AnkhSVN: <a class="moz-txt-link-freetext" href="http://ankhsvn.tigris.org">http://ankhsvn.tigris.org</a>
Blog: <a class="moz-txt-link-freetext" href="http://ankhsvn.com/blog">http://ankhsvn.com/blog</a>
RSS: <a class="moz-txt-link-freetext" href="http://ankhsvn.com/blog/Rss.aspx">http://ankhsvn.com/blog/Rss.aspx</a>
King Crimson lives in different bodies at different times and the
particular form which the group takes changes. When music appears,
which only King Crimson can play then, sooner or later, King Crimson
appears to play the music
</pre>
</blockquote>
</body>
</html>
--------------070101010801090009040807--