To interface or not to interface
Steven Schveighoffer
schveiguy at yahoo.com
Tue May 25 04:29:42 PDT 2010
On Tue, 25 May 2010 02:26:02 -0400, Kagamin <spam at here.lot> wrote:
> Recently I've hit a problem with collections in C#. Given classes
> class A {}
> class B {}
> And two collections Collection<A> and Collection<B> it's possible to
> concat them into an array A[]. The efficient way to do it is to use
> CopyTo(T[],int) method, but it accepts only array of exact collection
> item's type, so I had to change the Collection<B> type to Collection<A>.
Did you mean
class B : A {} ?
According to this page, it says that an exception could be thrown if "Type
T cannot be cast automatically to the type of the destination array."
This implies that a destination array type to which T could automatically
be cast should work.
http://msdn.microsoft.com/en-us/library/0efx51xw%28v=VS.100%29.aspx
But the larger point that compile-time code generation can help with this
is valid.
-Steve
More information about the Digitalmars-d
mailing list