473,385 Members | 1,925 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,385 software developers and data experts.

IList<> Question

Tom
Hi,

I have a simple Product Domain Entity class with just fields/properties. I
have a IList<Productthat I need to search for a particular Product object
based on a field/property ProductID. The only solution I could come up with
is a method that loops through the IList<Product(foreach) and looks at
each ProductID and returning the Product with the matching ProductID. Is
this the best solution?

Thanks
Nov 6 '06 #1
2 1521
Using Hashtable should be more efficient (for searching).

Wanjun

"Tom" <tb***@ball.comwrote in message
news:uE**************@TK2MSFTNGP03.phx.gbl...
Hi,

I have a simple Product Domain Entity class with just fields/properties.
I have a IList<Productthat I need to search for a particular Product
object based on a field/property ProductID. The only solution I could
come up with is a method that loops through the IList<Product(foreach)
and looks at each ProductID and returning the Product with the matching
ProductID. Is this the best solution?

Thanks

Nov 6 '06 #2
Hi,

Wanjun Yu wrote:
Using Hashtable should be more efficient (for searching).

Wanjun
Or, with generics, a Dictionary<string, Productwhere the key (the
"string") is the ProductID.

HTH,
Laurent
>
"Tom" <tb***@ball.comwrote in message
news:uE**************@TK2MSFTNGP03.phx.gbl...
>Hi,

I have a simple Product Domain Entity class with just fields/properties.
I have a IList<Productthat I need to search for a particular Product
object based on a field/property ProductID. The only solution I could
come up with is a method that loops through the IList<Product(foreach)
and looks at each ProductID and returning the Product with the matching
ProductID. Is this the best solution?

Thanks
--
Laurent Bugnion, GalaSoft
Software engineering: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
Nov 7 '06 #3

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

Similar topics

13
by: Sherif ElMetainy | last post by:
Hello I was just got VS 2005 preview, and was trying generics. I tried the following code int intArray = new int; IList<int> intList = (IList<int>) intArray; it didn't compile, also the...
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...
5
by: Lonifasiko | last post by:
I've got this in my code, that is, we're inside a class called Patient, so a Patient can have Appointments: private IList<Appointment> _appointments = null; public IList<Appointment>...
4
by: Mark | last post by:
I have a COM object that calls into a C# Forms library. The library can throw exceptions and I want to handle the exceptions in COM. Adam Nathan wrote a Microsoft sponsored book titled .Net and Com...
5
by: PJ | last post by:
I have a class definition : public class PagingList<T> : List<T> { private int pageSize, pageNumber; public PagingList() { pageSize = (this.Count == 0) ? 1 : this.Count;...
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...
1
by: Michael Primeaux | last post by:
Why does the generic SortedList and generic SortedDictionary not define any virtual members? Thanks, Michael
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...
35
by: Lee Crabtree | last post by:
This seems inconsistent and more than a little bizarre. Array.Clear sets all elements of the array to their default values (0, null, whatever), whereas List<>.Clear removes all items from the...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.