Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6902793
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T07:50:34+00:00 2026-05-27T07:50:34+00:00

Supposing I have this code public class Class1 { List<Class2> myClass2List = new List<Class2>;

  • 0

Supposing I have this code

public class Class1 
{
      List<Class2> myClass2List = new List<Class2>;
      public Class1() { } 
}

public class Class1List : List { }

public class Class2 
{
   public Class2() { };

   //Class2 objects will sit in a list that is an attribute of a Class1 object
   // class1 objects will be in a list that is an attribute of a Class3 object
   // is it possible for this method to access the  list in the Class3 object
   // without passing the list as a parameter.
   public void myClass2Method(){ }
}

public class Class3 
{
    Class1List myList = new Class1List();
    public Class3(){ }

    static void Main() 
    {
        Class3 myClass3Var = new Class3();
        // do something to fill myList;
         //  added some code to maybe make it a bit less muddy
        foreach (Class1 c1 in this.Class1List){
           foreach (class2 c2 in c1.myClass2List{
           // here is where I want to reference the Class1List attribute of the
           /// Class3 object - do I need to pass the list as a paramter?
           c2.MyClass2Method();
       }

     }
    }

}

Now supposing I have an instance of Class2 in myList in the instance of Class3. Is it possible for the Class2 method myClass2Method() to access myList wouthout passing the list as a parameter?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T07:50:35+00:00Added an answer on May 27, 2026 at 7:50 am

    You can, but you dont want to.
    you can add a member to class2 of type Class1List and when you add the instances of class2 to mylist you can set said member to mylist and than use the local member in the function.
    BUT doing so is bad for you, dont do it, your deisgn is wrong and you need to ask a different question (how to design _____).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Supposing I have the C# code line: var myList = new List {1,2,3}; And
This is a learning exercise in expression trees. I have this working code: class
Supposing I have a list/tuple like this: MyLocation = 'DE' ( ('Pencils', 'Artists Pencils',
I have a code like this: <s:select id=s list=list listKey=id listValue=displayValue> When I get
I'm sure I'm going to have to write supporting javascript code to do this.
Supposing I have this: foo bar 1 and foo bar 2 How can I
Supposing to have something like this: #include <map> int main(){ std::map<int,int> m; m[1] =
Suppose I have a function like this: public void AddEntry(Entry entry) { if (entry.Size
I have a rich:dataTable . I want to hide a row with this code:
So, let's say I have this code (VB.Net): Sub Main() dim xxx as string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.