From: Kenneth Cochran on
On 2/11/2010 4:29 PM, Peter Duniho wrote:
> Minor correction. The above would in fact compile, because it's got an
> explicit cast. But it would throw an exception when executed.

Actually it does compile and run because List<T> implements IList as well.
From: Peter Duniho on
Kenneth Cochran wrote:
> On 2/11/2010 4:29 PM, Peter Duniho wrote:
>> Minor correction. The above would in fact compile, because it's got an
>> explicit cast. But it would throw an exception when executed.
>
> Actually it does compile and run because List<T> implements IList as well.

Ah, of course. How careless of me. That's what I get for failing to
post the correct code example in the first place. I lose track of what
the code is doing.

Note that an assignment/addition via the List<T> implementation of IList
would fail unless the type of the object is of the correct type. Thus,
the explicit cast succeeds, but adding an object of the wrong type (as
in my second example in that post) will fail at run-time.

Pete
First  |  Prev  | 
Pages: 1 2
Prev: f
Next: TcpClient buffer size limit?