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

Inheriting from CollectionBase

I wanted to create a type-safe collection by inheriting from CollectionBase.

Public Class MyCollection : Inherits CollectionBase

I found that IList.Add did not allow the setting of a "key" to identify an
object added to the collection.
So to implement a "key" similar to the parameter allowed by the standard
Collection object do I have to create my own array to store the "keys" and
manage it within my class MyCollection? I can't see how I will be able to
make sure my array of "keys" will always point to the correct items in the
collection.
Seems a headache, would like to know if there is some other class I can
inherit from to gain methods more similar to that of Collection.

--
Thanks for any help,
Shayne H
Nov 20 '05 #1
2 4018
Shayne,
If you want to store elements by key, you should inherit from
DictionaryBase.

If you want to index elements by both key & integer, then I would suggest
inheriting from System.Collections.Specialized.NameObjectCollectio nBase.

Hope this helps
Jay

"Shayne H" <shaynehATlycosSPAMGOTOHELLcoDOTuk> wrote in message
news:%2******************@tk2msftngp13.phx.gbl...
I wanted to create a type-safe collection by inheriting from CollectionBase.
Public Class MyCollection : Inherits CollectionBase

I found that IList.Add did not allow the setting of a "key" to identify an
object added to the collection.
So to implement a "key" similar to the parameter allowed by the standard
Collection object do I have to create my own array to store the "keys" and
manage it within my class MyCollection? I can't see how I will be able to
make sure my array of "keys" will always point to the correct items in the
collection.
Seems a headache, would like to know if there is some other class I can
inherit from to gain methods more similar to that of Collection.

--
Thanks for any help,
Shayne H

Nov 20 '05 #2
Thanks a heap
Nov 20 '05 #3

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

Similar topics

5
by: Steve M | last post by:
I have subclassed CollectionBase. I have also implemented GetEnumerator(). I have tried to set the DataSource of a DataGrid to an instance of my subclass. However, the items in the grid are not...
7
by: m. pollack | last post by:
Hi all, I've been using the CollectionBase class to implement a strongly-typed collection, but I have noticed that the RemoveAt method does not seem to call the "On" hook methods (OnRemove,...
11
by: Noah Coad [MVP .NET/C#] | last post by:
How do you make a member of a class mandatory to override with a _new_ definition? For example, when inheriting from System.Collections.CollectionBase, you are required to implement certain...
5
by: Eric Johannsen | last post by:
I have a simple object that inherits from CollectionBase and overrides the Count property: namespace MyTest { public class CollTest : System.Collections.CollectionBase { public override int...
2
by: Scott Reynolds | last post by:
I am having a problem exposing a class inherited from the collection base class as a webservice. If I expose the collection on a web page all works well and I am very happy. However when I try and...
2
by: Mark Overstreet | last post by:
I am writing custom collections for my business objects but I need support for the foreach construct. I also need key support so I am inheriting from NameObjectCollectionBase. I need to support...
1
by: Matthew Roberts | last post by:
Howdy Everyone, I am having trouble understanding the process of creating a type-safe collection by inheriting from the CollectionBase class. I have done it plenty of times, but now that I sit...
1
by: Kyle Novak | last post by:
I have a question about strongly typed objects when looping through a collection based on the CollectionBase object and using a For..Each loop. I have 2 objects: -Invoice: Holds all properties...
5
by: jc | last post by:
RE: Two Classes with the same Data Structure.. saving code? Inheriting a structure? I have two classes. One in Inherits System.Collections.CollectionBase, the other does not, but they both have...
3
by: Tony Johansson | last post by:
Hello! Sorry for opening up this task again. I want to fully understand this List that is return from CollectionBase. According to you is List in CollectionBase implemented something like...
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: 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: 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...
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.