473,395 Members | 2,783 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Object Question

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
Aug 24 '06 #1
2 1152
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.
--
HTH
Stoitcho Goutsev (100)

"randy" <ra***@d.comwrote in message
news:uB**************@TK2MSFTNGP03.phx.gbl...
>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

Aug 24 '06 #2
Im guessing you're using 2.0, as you have "partial" in you definition.

Go here
http://www.coders-lab.dotnetnuke-por...2/Default.aspx

Finding an object in a List<collection
Sorting generic lists

Read the whole thing, but the 2 items above are what youre looking for I
think.

You can also check out my blog, where I did some coding using the document
above as a resource.
http://sholliday.spaces.live.com/ 6/5/2006 entry.


"randy" <ra***@d.comwrote in message
news:uB**************@TK2MSFTNGP03.phx.gbl...
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


Aug 24 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sunaina | last post by:
This is the first program I am writing using PHP and Mysql. I am creating a game where user thinks of an object and my program guesses the object while asking series of yes/no questions. All a...
6
by: Chris S. | last post by:
I'm trying to make a graphical editor and browser for Pickled files. One aspect I'm not sure about is how to detect multiple references to the same data. For instance, say I had the Pickled...
4
by: Tom | last post by:
I want to open a recordset object on an .asp page. When I open the recordset I would like to use a stored procedure that expects a parameter to be passed for the stored procedure. I will then use...
4
by: Mark D. Anderson | last post by:
About a month ago Richard Cornford did an interesting analysis of a memory leak in jscript (internet explorer) when there are "circular" references between DOM objects and (real) jscript objects:...
6
by: Luke | last post by:
Here is my emails to Danny Goodman (but probably he is very busy so he didn't answered it). First email(simple): Subject: JavaScript Arrays " We all know the array can act like HashMap, but is...
100
by: E. Robert Tisdale | last post by:
What is an object? Where did this term come from? Does it have any relation to the objects in "object oriented programming"?
6
by: Tom | last post by:
I have a problem, to which I have been unable to find a solution for days now, after checking numerous references (both in books and online). Perhaps someone here can help. Here's my problem: ...
7
by: Martin Robins | last post by:
I am currently looking to be able to read information from Active Directory into a data warehouse using a C# solution. I have been able to access the active directory, and I have been able to return...
26
by: yb | last post by:
Hi, Is there a standard for the global 'window' object in browsers? For example, it supports methods such as setInterval and clearInterval, and several others. I know that w3c standardized...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.