Object Question

R

randy

I need to loop through a collection of objects (see below) based on the
field vendorName. I basically need to sort by vendorID and then pull the
product info from each vendor. There are multiple products per vendor. Any
ideas?


public partial class Product
{
private string productID;
private string productName;
private string vendorID;
private string vendorName;
.....
}

Thanks
 
S

Stoitcho Goutsev \(100\)

randy,

There are several solutions to the problem.
1. If you use generic collection such as ArrayList you can create custom
comparer - a class that implment IComparer method and then use the
vendorName for comparing the objects. Once you have this use ArrayList.Sort
overload that accepts comparer object.

2. Using SortedList class. This class is key/value collection and sorts the
elements by the key value. When adding the objects use vendorName as key.

There are of course other possible solutions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top