Microsoft Developer Network > 포럼 홈 > .NET Base Class Library > Referencing a Collections Item's Parent Class (Containing Class)
질문하기질문하기
 

답변됨Referencing a Collections Item's Parent Class (Containing Class)

답변

  • 2009년 11월 6일 금요일 오후 10:36Reed Copsey, Jr. 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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
    • 답변으로 표시됨Constansere 2009년 11월 7일 토요일 오후 5:57
    •  

모든 응답

  • 2009년 11월 6일 금요일 오후 10:36Reed Copsey, Jr. 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     답변됨
    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
    • 답변으로 표시됨Constansere 2009년 11월 7일 토요일 오후 5:57
    •