mr_zack Posted February 14, 2003 Posted February 14, 2003 Hello, I need some help implementing a collection class. I don't understand some of the methods I need to implement. I have marked the methods I need help with as such: ??? What do I do here? Here is what I have: public class ParamsCollection : System.Collections.CollectionBase { public ParamsCollection() { } public new int Count { get { return List.Count; } } public override bool Equals(object obj) { return false; ??? What do I do here? } public override int GetHashCode() { return 0; ??? What do I do here? } public override string ToString() { return null; ??? What do I do here? } public new void Clear() { ??? What do I do here? Should this remove all objs from col? } public new System.Collections.IEnumerator GetEnumerator() { return null; ??? What do I do here? } public new System.Type GetType() { return null; ??? What do I do here? Should this return the type of object in collection? } public new void RemoveAt(int pIndex) { List.RemoveAt(pIndex); } public void Add(Parameter pParameter) { List.Add(pParameter); } public Parameter this[int pIndex] { get { return (Parameter)List[pIndex]; } set { List[pIndex] = value; } } } Quote
*Experts* Bucky Posted February 14, 2003 *Experts* Posted February 14, 2003 When you inherit from a class such as CollectionBase, you do not need to override every single member like you need to do when implementing an interface. For example, the Clear method of the base class will clear the List collection, so you don't need to override it, unless you want to add some extra functionality. ToString could return whatever you want it to... it could be a string representing the class's type, or it could be a delimited string returning all the elements in the collection, for example. GetType simply returns your class's type... As far as I can tell, it can't be overriden (in VB.NET at least, since GetType is a keyword). For the Equals function, compare each element in the collection passed to it to return a true value if everything matches up. Otherwise, return false. Again, the base class probably will handle this just fine. The same holds true for GetHashCode, and any other method you're not sure of; if you don't know what to put, then let the base class deal with it. Although I'm sure someone here will follow up with some better ideas for the overrides... :) Quote "Being grown up isn't half as fun as growing up These are the best days of our lives" -The Ataris, In This Diary
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.