473,800 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

IList<> Question

Tom
Hi,

I have a simple Product Domain Entity class with just fields/properties. I
have a IList<Productth at 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(f oreach) and looks at
each ProductID and returning the Product with the matching ProductID. Is
this the best solution?

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

Wanjun

"Tom" <tb***@ball.com wrote in message
news:uE******** ******@TK2MSFTN GP03.phx.gbl...
Hi,

I have a simple Product Domain Entity class with just fields/properties.
I have a IList<Productth at 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(f oreach)
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<stri ng, Productwhere the key (the
"string") is the ProductID.

HTH,
Laurent
>
"Tom" <tb***@ball.com wrote in message
news:uE******** ******@TK2MSFTN GP03.phx.gbl...
>Hi,

I have a simple Product Domain Entity class with just fields/properties.
I have a IList<Productth at 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(f oreach)
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
2714
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 following didn't compile
4
25416
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 following error: Argument '1': cannot convert from 'GenericsPOC.ArticleCollection' to 'System.Collections.Generic.IList<object>' I tried casting specifically to IList<object> but then I get a runtime error: Unable to cast object of type...
5
13643
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> Appointments { get
4
3903
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 the complete interoperability guide which shows examples of how to do this. Below please find the book example code for getting extended error information from a V-Table bound .Net component. This code does not compile because the compiler gives...
5
1922
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; pageNumber = 1; }
2
4535
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 ReadOnlyCollection<T> : IList<T>,ICollection<T>,IEnumerable<T> ...
1
4716
by: Michael Primeaux | last post by:
Why does the generic SortedList and generic SortedDictionary not define any virtual members? Thanks, Michael
6
6007
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 typeof(IList).IsAssignableFrom(typeof(IList<string>)) --false
35
5898
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 list. That part makes a reasonable amount of sense, as you can't actually take items away from an Array. However, there doesn't seem to be a way to perform the same operation in one fell swoop on a List<>. For example:
0
9690
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9550
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10501
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10273
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10250
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7574
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5603
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3764
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2944
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.