searching an IList?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have the following:
User bllCANs = new User();
IList CANlist = bllCANs.GetListofUsers();

This will return a set of data with about 9 fields per row. I want to
search through this IList to find a particular value. For example, one of
the fields is LastName. I want to search to see if a particular last name is
in this IList. I was trying IndexOf, but I just can't get the exact syntax
of exactly how to call it. Any suggestions?
 
KMZ_state,

An IList implementation should honor the IComparable interface
implementation that an object has on it. However, it seems like you might
have other criteria for searching your list which might vary. In this case,
I would get an array of items from the IList implementation, and call the
FindAll method, passing a delegate which will perfrom the comparison
criteria.

Hope this helps.
 
KMZ_state said:
I have the following:
User bllCANs = new User();
IList CANlist = bllCANs.GetListofUsers();

This will return a set of data with about 9 fields per row. I want to
search through this IList to find a particular value. For example, one of
the fields is LastName. I want to search to see if a particular last name is
in this IList. I was trying IndexOf, but I just can't get the exact syntax
of exactly how to call it. Any suggestions?

IndexOf finds an instance. It can't find things with certain fields.
You've got to iterate through the loop (maybe with foreach):

foreach (User user in CANlist)
if (user.LastName == yourLastName)
// found

-- Barry
 
OK, I follow that. I put this all into the TextChanged method and can't seem
to get it to fire? What am I missing? Sorry if these questions are simple -
I am new at this! Thanks so much.
 
KMZ_state said:
OK, I follow that. I put this all into the TextChanged method and can't seem
to get it to fire? What am I missing? Sorry if these questions are simple -
I am new at this! Thanks so much.

I don't know. This code works for me:

---8<---
using System;
using System.Windows.Forms;

class App
{
static void Main()
{
Form form = new Form();
TextBox box = new TextBox();
box.Parent = form;
box.TextChanged += delegate
{
form.Text = box.Text;
};
Application.Run(form);
}
}
--->8---

But I have no idea what your code is doing. Are you sure it's the right
control?

-- Barry
 

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

Back
Top