Microsoft Developer Network > Página Inicial dos Fóruns > .NET Base Class Library > Referencing a Collections Item's Parent Class (Containing Class)
Fazer uma PerguntaFazer uma Pergunta
 

RespondidoReferencing a Collections Item's Parent Class (Containing Class)

Respostas

  • sexta-feira, 6 de novembro de 2009 22:36Reed Copsey, Jr. Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    There is no way to do this, unless you've saved the parent inside of the class.

    This is because there really can't be a way to do it.  Say you have nothing but an instance of "SomeClass" -

        SomeClass theClassInstance = classList[3];

    There'd be no way to get "classList" from that, since it could be:

    1) Not stored in a collection
    2) Stored in a collection multiple times
    3) Stored in multiple collections

    If, however, you need this for your particular scenario, what you could do is have a custom collection implementation, and save a reference to it in each member.
    Reed Copsey, Jr. - http://reedcopsey.com
    • Marcado como RespostaConstansere sábado, 7 de novembro de 2009 17:57
    •  

Todas as Respostas

  • sexta-feira, 6 de novembro de 2009 22:36Reed Copsey, Jr. Medalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuárioMedalhas de usuário
     Respondido
    There is no way to do this, unless you've saved the parent inside of the class.

    This is because there really can't be a way to do it.  Say you have nothing but an instance of "SomeClass" -

        SomeClass theClassInstance = classList[3];

    There'd be no way to get "classList" from that, since it could be:

    1) Not stored in a collection
    2) Stored in a collection multiple times
    3) Stored in multiple collections

    If, however, you need this for your particular scenario, what you could do is have a custom collection implementation, and save a reference to it in each member.
    Reed Copsey, Jr. - http://reedcopsey.com
    • Marcado como RespostaConstansere sábado, 7 de novembro de 2009 17:57
    •