Prev: f
Next: TcpClient buffer size limit?
From: Kenneth Cochran on 11 Feb 2010 16:58 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 11 Feb 2010 17:42
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 |