1 Replies - 5831 Views - Last Post: 08 April 2008 - 04:42 AM Rate Topic: -----

#1 Yagnesh Patel   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 08-April 08

How to search thru Array based on value of the combobox?

Posted 08 April 2008 - 03:09 AM

Hi,
I want to search the array of user-defined object, say user-defined class is as below.
public class ServiceTypes
	 {
	 public int ServiceID;
	 public string ServiceName;
	 public int VendorID;
	 }



On the windows form, I have one combo box control thru which I can get VendorID.

Now, I want to search thru the ServiceTypes - array based on the value of VendorID selected in the combo.

Note: I can not use Array.FindAll, as I need to search ServiceTypes based on the value selected in VendorID combo.

Can anyone help to find good performance solution? - I know about search thru the array and prepare new based on the VendorID.

Thanx
Yagnesh

Is This A Good Question/Topic? 0
  • +

Replies To: How to search thru Array based on value of the combobox?

#2 baavgai   User is offline

  • Dreaming Coder
  • member icon


Reputation: 7507
  • View blog
  • Posts: 15,558
  • Joined: 16-October 07

Re: How to search thru Array based on value of the combobox?

Posted 08 April 2008 - 04:42 AM

View PostYagnesh Patel, on 8 Apr, 2008 - 06:09 AM, said:

Note: I can not use Array.FindAll, as I need to search ServiceTypes based on the value selected in VendorID combo.


You can use FindAll, you just have to know how to ask the question. ;)

Here's the code:
ServiceTypes[] FindAllTest(ServiceTypes[] list, int vendorId) {
   return Array.FindAll(list,
      delegate(ServiceTypes item) { return item.VendorID == vendorId; }
   );
}



Also, look into List<ServiceTypes>, it's generally a better solution to an array. Delegates are exceptionally useful tools. If you start to use Generics, then even more so.

Hope this helps.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1