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

  • SEARCH
  • Home
  • 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 5981457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:56:47+00:00 2026-05-22T21:56:47+00:00

I have this object Object1 defined as public Object1(String item, List<Object2> obj2) in a

  • 0

I have this object Object1 defined as public Object1(String item, List<Object2> obj2) in a class (whilst Object2 is defined in another class as public Object2(String item1, String item2))

Next, in the main program, I’m creating a list of Object1 objects:

public static List<Object1> obj1 = new List<Object1>();

List<Object2> obj2 = new List<Object2>();:

obj1.add("first", obj2);
obj1.add("second", obj2);
obj1.add("third", obj2);

Next I want to add some objects into obj2 for every obj1 specifically:

obj1[0].Obj2.Add(new Object2("first","first");
obj1[0].Obj2.Add(new Object2("first","second");
obj1[1].Obj2.Add(new Object2("second","first");
obj1[1].Obj2.Add(new Object2("second","second");
obj1[2].Obj2.Add(new Object2("third","first");
obj1[2].Obj2.Add(new Object2("third","second");

Now the problem is that, for example, obj[0].Obj2.Count is 6, and it’s the same for obj[1].Obj2.Count and so on. How should I populate obj2 so that each Obj2 would be different depending on obj1[]? For example obj1[0].Obj2 different from obj1[1].Obj2 and obj1[0].Obj2.Count to be 2.

Please excuse me if I didn’t explain my problem properly or didn’t write all the necessary details. Thank you for your answers in advance.

  • 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-22T21:56:48+00:00Added an answer on May 22, 2026 at 9:56 pm

    If I understand you well, you should have a different list for each Object1

    obj1.add("first", new List<Object2>());
    obj1.add("second", new List<Object2>());
    obj1.add("third", new List<Object2>());
    

    Have you considered using a Map ?

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

Sidebar

Related Questions

I have two classes declared like this: class Object1 { protected ulong guid; protected
I have a simple class as defined below: public class Person { int _id;
I have a model that looks something like this: public class SampleModel { public
I have three java types as defined below: Main.java: import java.util.Arrays; import java.util.List; public
I am using asp.net MVC2. I have a model defined as public class Department
Consider this container: public class ItemInfo : DependencyObject { public string Name { get;
I have this object graph, I want to map: abstract Account (username, password, ...)
In my qt app I have this object, filled before setting up my QTreeWidget's
Suppose I have a design like this: Object GUI has two objects: object aManager
Suppose I have this code: var myArray = new Object(); myArray["firstname"] = "Bob"; myArray["lastname"]

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.