Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is it a good design to have a Class with List of class same class objects

Status
Not open for further replies.

john121

Programmer
Oct 18, 2007
9
0
0
GB
Hi

We have a requirement to create a class like this

Class Bundle
{
int BundleId;
string BundleName;
double NRC;
double ARC;
List<Bundle> BundleList;
int NestedBundleId; //This is the parent BundleId
}

The reason we trying this is we need an xml output like this
<Bundle>
<BundleId>
<BundleName>
<NRC>
<ARC>
<Bundle> //This is based on the nested bundleId
<BundleId>
<BundleName>
</Bundle>
<NRC>
<ARC>
</Bundle>

Can you guys have your opinion on what is the best way to get this structure done as I thought about the circular reference initially, but in this instance there is no circular reference as it just creates new list of bundles

what we doing in c# is
Bundle bundle = new Bundle();
List<Bundle> nestedBundleList= new List<Bundle>
bundle.BundleList = nestedBundleList;

Thanks
 
Let's look at your XML... you have an issue already with it.... you have two NRC/ARC in the root node... Do you mean to have that in the nested node and not the root node?

I would probably just use the XML node writing functions already part .Net.

Yours:
<Bundle>
<BundleId>
<BundleName>
<NRC>
<ARC>
<Bundle> //This is based on the nested bundleId
<BundleId>
<BundleName>
</Bundle>
<NRC>
<ARC>
</Bundle>

What I suspect you want:
<Bundle>
<BundleId>
<BundleName>
<NRC>
<ARC>
<Bundle> //This is based on the nested bundleId
<BundleId>
<BundleName>
<NRC>
<ARC>
</Bundle>
</Bundle>

Walt
IT Consulting for Robert Half
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top