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

custom collection

Hi!
i have a class "user" with 3 properties: userIid, userName, userEmail and
another class that is a collection of users "userCollection":
namespace meta01.colecciones
{

public class userCollection: System.Collections.CollectionBase
{
public userCollection()
{
}

public user this[ int index ]
{
get
{
return( (user) List[index] );
}
set
{
List[index] = value;
}
}

public void add(user oUser)
{
List.Add(oUser);
}

public void remove(user value)
{
List.Remove(value);
}
public user getUser(int i)
{
return (user)List[i];
}
public int IndexOf( user value )
{
return (List.IndexOf(value)) ;
}

public void Insert(int index, user value)
{

this.List.Insert(index, value);

}

}
}
In my webform i create some users like this:
oUserCollection.add(new user(1,"user1","11*@or.com"));
oUserCollection.add(new user(2,"user2","22*@or.com"));
oUserCollection.add(new user(3,"user3","33*@or.com"));
oUserCollection.add(new user(4,"user4","44*@or.com"));
I can list the contents of the collection but how can i get an user by its
userID.
If i want the details of user1 how can i get them???
There's a better way of doing this??

Thank you very much.
Nov 16 '05 #1
1 1216
I usually do it like this:

public getUserById(int userId)
{
foreach(user userobject in List)
{
if(userobject.userId = userId) return user;
}
return null;
}

Optimization?
If you have large collections of users and you do this operation often you
could base the usercollection on a hash tabel and use the userid as key.
Looking up a user would probably then be more efficient.

cheers,
mortb

"Oterox" <ot****@asp404.com> wrote in message
news:eL**************@TK2MSFTNGP11.phx.gbl...
Hi!
i have a class "user" with 3 properties: userIid, userName, userEmail and
another class that is a collection of users "userCollection":
namespace meta01.colecciones
{

public class userCollection: System.Collections.CollectionBase
{
public userCollection()
{
}

public user this[ int index ]
{
get
{
return( (user) List[index] );
}
set
{
List[index] = value;
}
}

public void add(user oUser)
{
List.Add(oUser);
}

public void remove(user value)
{
List.Remove(value);
}
public user getUser(int i)
{
return (user)List[i];
}
public int IndexOf( user value )
{
return (List.IndexOf(value)) ;
}

public void Insert(int index, user value)
{

this.List.Insert(index, value);

}

}
}
In my webform i create some users like this:
oUserCollection.add(new user(1,"user1","11*@or.com"));
oUserCollection.add(new user(2,"user2","22*@or.com"));
oUserCollection.add(new user(3,"user3","33*@or.com"));
oUserCollection.add(new user(4,"user4","44*@or.com"));
I can list the contents of the collection but how can i get an user by its
userID.
If i want the details of user1 how can i get them???
There's a better way of doing this??

Thank you very much.

Nov 16 '05 #2

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

Similar topics

3
by: Anthony Bouch | last post by:
Hi I've been reading using the XmlSerializer with custom collections. I've discovered that when serializing a custom collection (a class that implements ICollection, IList etc.) the...
0
by: panik | last post by:
Hi, I have a custom collection that implements CollectionBase. The collection is called Sensors and contains a list of Sensor objects. There is the usual index using an integer (Sensors). ...
8
by: Tinus | last post by:
Hello all, I've create a custom control (UserControl) and have a custom Item Collection. The control is a custom calendar which is draw using the Graphics Rectangle etc. functions. It is drawn...
1
by: Jeff S | last post by:
I'm storing a list of widgets in a database. The list changes infrequently (twice per week at most), and is relatively short (200 items at most, with very little detail per item). A small subset of...
21
by: One Handed Man \( OHM - Terry Burns \) | last post by:
When using a custom control. In order to check and see if values have changed one has to implement the IPostBackDataCollection interface. The values returned for the control seem to be simply a...
6
by: kbs | last post by:
Hi, I'm looking for some good examples that illustrate how to code a web service that exposes a custom collection so that the properties of the collection are accessible on the client without...
19
by: Jamey Shuemaker | last post by:
I'm in the process of expanding my knowledge and use of Class Modules. I've perused MSDN and this and other sites, and I'm pretty comfortable with my understanding of Class Modules with the...
4
by: Stuart | last post by:
I hope someone can shed some light on an error I've been experiencing for sometime now, but can no longer continue to ignore :-( I've created a custom entity class which implements IEditableObject....
7
by: Dale | last post by:
I have a design question. I am creating a custom collection of products. The unique key for the products is productId which is an integer. By default, IndexOf(object obj), when obj is an int,...
0
by: Pieter | last post by:
Hi, I'm using NHibernate 1.2 (CR1), and I'm using a custom list (inherited from BindingList(Of T) ) for all my lists. The NHibernate documentation told me that I had to implement...
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: 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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.