casting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • David

    casting

    hello...

    i've a litlle problem and don't know how to handle this...

    i have collection (System.Collect ions.ArrayList) with number of diffrent
    objects within it...
    now i need to get all the objects from that collection wich are dirived from
    some inteface...
    how can i do that..?

    i tried to use ArrayList::ToAr ray (Type type) method, but it don't work!
    or may be i'm not using it right way...
    ------
    sorry for my english...
    ------
    David I.


  • Jon Skeet [C# MVP]

    #2
    Re: casting

    David <david_tm3@hotm ail.com> wrote:[color=blue]
    > i've a litlle problem and don't know how to handle this...
    >
    > i have collection (System.Collect ions.ArrayList) with number of diffrent
    > objects within it...
    > now i need to get all the objects from that collection wich are dirived from
    > some inteface...
    > how can i do that..?
    >
    > i tried to use ArrayList::ToAr ray (Type type) method, but it don't work!
    > or may be i'm not using it right way...[/color]

    Something like:

    ArrayList interfaceImplem entors = new ArrayList();

    foreach (object candidate in candidateList)
    {
    if (candidate is MyInterface)
    {
    interfaceImplem entors.Add(cand idate);
    }
    }

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...