I think you got the interface idea wrong. Many classes do implement, for
example, the IEnumerable interface; arrays do so, ArrayList, but also
HashTable and many other classes. Still you can't cast a HashTable to an
array or vice versa - they are unrelated classes and the only way to
"convert" them is to copy all the data item by item. The only thing you can
do is cast each of them to the IEnumerable interface. The idea is to write
code that only accesses classes through interfaces, so you can easily change
the implementation, as in:
void Output (IEnumerable lst)
{ foreach (object x in lst) Console.Writeline(x); }
This function will work for arrays, arraylists, hashtables...
Hope this helps,
Niki
"Clint Hill" <Clint
(E-Mail Removed)> wrote in
news:E2497A2F-5EC3-44A5-9ECC-(E-Mail Removed)...
> I am working on a project that I would like to have some extensibility for
> later. So with this I am using interfaces to pass objects to derived
classes.
> However I am running into a situation where two seperate classes won't
cast
> each other even though they implement the same interface. The classes are
> identical yet won't convert. Here is (briefly) what I am talking about:
>
> public interface IReturnObject
> {
> Guid ID { get; set; }
> string Status { get; set; }
> string Message { get; set; }
> }
>
> public class Result : IReturnObject
> {
> //implements code here
> }
>
> public class Response : IReturnObject
> {
> //implements code here
> }
>
>
> NOTE: The above two classes are in different namespaces such that Result
is
> in System.Application1.Result and Response is in
System.Application.Response.
>
> So when I use this in a client app and try to cast these two classes
against
> each other it compiles but at runtime I get "Specified cast is not valid"
> with a System.ArguementException.
>
> Any help would be greatly appreciated.