C# through ASP.Net 2.0.
In a datatable I have two columns of IDs, attributeId and productAttributeID.
I want to loop through this table and ‘group’ them in such a way that productAttributeIds have one or more attributeIds associated with them.
For example, in pseudo-code this is what I’m doing
For each datarow in myDatatable.rows
Insert into myarray at index(productattributeId) - corresponding attributeId
end foreach
So this will loop and each time the same productAttributeId is present, the attributeId will be added to the array corresponding.
Obviously this won’t work as arrays need to be size declared etc.
I’ve tried multi-dimensional arrays, jagged arrays, arraylists, lists of arraylists all to no avail, my code is failing yet I know in theory what I want to do.
I would, personally, use a
Dictionary<int, List<int>>:You can then easily get all of the product attributes for an attribute: