473,402 Members | 2,050 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,402 software developers and data experts.

searching an IList?

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?
Jul 11 '06 #1
4 19410
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.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"KMZ_state" <KM******@discussions.microsoft.comwrote in message
news:5E**********************************@microsof t.com...
>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?

Jul 11 '06 #2
KMZ_state <KM******@discussions.microsoft.comwrote:
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

--
http://barrkel.blogspot.com/
Jul 11 '06 #3
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.

"Barry Kelly" wrote:
KMZ_state <KM******@discussions.microsoft.comwrote:
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

--
http://barrkel.blogspot.com/
Jul 11 '06 #4
KMZ_state <KM******@discussions.microsoft.comwrote:
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

--
http://barrkel.blogspot.com/
Jul 11 '06 #5

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

Similar topics

4
by: emma middlebrook | last post by:
Hi Straight to the point - I don't understand why System.Array derives from IList (given the methods/properties actually on IList). When designing an interface you specify a contract. Deriving...
3
by: Chris | last post by:
Hi, the specs for System.Array are : public abstract class Array : ICloneable, IList, ICollection, IEnumerable but I can't use any of the functions presented by IList in my code ...
13
by: cody | last post by:
why arent there some util functions for IList for example Sort()? -- cody Freeware Tools, Games and Humour http://www.deutronium.de.vu || http://www.deutronium.tk
2
by: Michael Groeger | last post by:
Hi, is it possible to determine if the PropertyType of a property support IList? We are inspecting all properties of a Type and we need to care about the properties which have a type which...
4
by: KC | last post by:
Could some one explain to me the casting rules for sending generic lists, ex. List<Person>, to a function that accepts List<object>? I cannot get the following easy-cheesy app to work. I get the...
3
by: Giovanni Bassi | last post by:
Hello All, I have a class implementing IList and a global object of this class type. I have two different form objects. One has a ListBox and the other has ComboBox. Both of their datasources...
2
by: Lucian Wischik | last post by:
Does ReadOnlyCollection<T> really implement IList<T>, like it claims to do? ... When I right-click on ReadOnlyCollection and look at its definition, it says this: public class...
6
by: Nick | last post by:
I have a code that returns data in IList. My webGrid doesn't allow me to sort with IList returned, it say it only suports DataView, DataTable and DataSet, not IEnumerable. I don't know how to...
6
by: nicolas.rolland | last post by:
Would anyone know the reson why IList<Tdoes not implements IList ?? This results in strange behaviours, like typeof(IList).IsAssignableFrom(typeof(List<string>)) --true...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.