473,385 Members | 1,474 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.

Generics for custom collections

I am developing a new management system for my company, and with it have 3
layers of functionality written in VB.NET 2.0. In the business logic layer I
have a user class which contains all user information. I also would like to
put in a userCollection class for all my users. There are many other classes
like this on as well. However, what is the best way to do my collections? I
would like them so that a userCollection can only contain user items and so
on. I have seen that I could write my own collection class by inheriting
from the collection base. Would it be easier if I used generics instead?
The syntax is not correct but something like Private userCollection as
Collection(of Users) can this be done? If so, is it easier than developing
100+ seperate collection classes? How would I go about generics?
Mar 2 '06 #1
3 1868
"Nick" <nt********@online.nospam> wrote
[Custom Collections]
However, what is the best way to do my collections? I would like
them so that a userCollection can only contain user items and so
on.
Sounds like a job for Generics...
I have seen that I could write my own collection class by inheriting
from the collection base.
Ick. You may as well code in Perl, Cobol or Fortran if you're going to do
that...
Would it be easier if I used generics instead?
Heck yea.
The syntax is not correct but something like Private userCollection as
Collection(of Users) can this be done? If so, is it easier than
developing
100+ seperate collection classes? How would I go about generics?


The code for the generic collection looks like:

// The Custom Class
public class CustomClass
{
public string Name;
}

// The Custom Collection
public class CustomCollection : List<CustomClass>
{
// Add in any custom constructors you want here...
}

--
Chris Mullins
Mar 3 '06 #2
How would it look in VB as I am not great with C# yet

"Chris Mullins" wrote:
"Nick" <nt********@online.nospam> wrote
[Custom Collections]
However, what is the best way to do my collections? I would like
them so that a userCollection can only contain user items and so
on.


Sounds like a job for Generics...
I have seen that I could write my own collection class by inheriting
from the collection base.


Ick. You may as well code in Perl, Cobol or Fortran if you're going to do
that...
Would it be easier if I used generics instead?


Heck yea.
The syntax is not correct but something like Private userCollection as
Collection(of Users) can this be done? If so, is it easier than
developing
100+ seperate collection classes? How would I go about generics?


The code for the generic collection looks like:

// The Custom Class
public class CustomClass
{
public string Name;
}

// The Custom Collection
public class CustomCollection : List<CustomClass>
{
// Add in any custom constructors you want here...
}

--
Chris Mullins

Mar 3 '06 #3
That would be:

Public Class CustomClass
End Class

Public Class CustomCollection
Inherits List(Of CustomClass)

End Class

Mar 3 '06 #4

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

Similar topics

1
by: Helium | last post by:
Is there any need for "System.Collections.Queue" any more? OK, .Net made the mistake to start without generics, but that is fixed now. Languages without support for generics could use...
8
by: Chris Dunaway | last post by:
The next version of VS.Net (Whidbey) promises to add generics support to VB. I have a vague remembrance of Templates in C++, but I guess I need a refresher. What will generics allow us to do? ...
4
by: _DS | last post by:
I need to create arrays of a custom data type (which is composed of various strings, ints, the usual). The original was built using CollectionBase. I was thinking about redesigning to use...
6
by: nick_nw | last post by:
Hi, What significant advantages do generics give me over passing objects around as 'object' and casting when needed? I was asked this recently and started off by saying, "well of course...
3
by: Showjumper | last post by:
Back in asp.net 1.1 i made custom collection classes per Karl Seguin's article On the Way to Mastering ASP.NET: Introducing Custom Entity Classes to take advantage of strongly typed data. Now with...
4
by: SHEBERT | last post by:
Here is an example of a SortedList that works as a datasource to the ComboBox and a generic SortedList<that does not works as a datasource to the ComboBox. Why? If I use List and generic List<>,...
7
by: SpotNet | last post by:
Hello NewsGroup, Reading up on Generics in the .NET Framework 2.0 using C# 2005 (SP1), I have a question on the application of Generics. Knowingly, Generic classes are contained in the...
4
by: ludwig.stuyck | last post by:
Hello, I updated my article on generics with databinding and serialization/ deserialization. Summary: Generics are one of the most useful improvements in the .NET 2.0 framework. In this...
7
by: =?Utf-8?B?Q29kZVJhem9y?= | last post by:
Can someone explain a few things about collections to me. In C# 2 generics, you can create a collection class by inheriting from System.Collections.ObjectModel.Collection. Using this you can...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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...

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.