Trouble with CollectionBase
-
I created a collection class using the .NET help files, but when I add objects to the collection, it appears as though the each new object copies itself throughout the collection--all objects in the collection become equal to the new added object. Anyone run into this before? Here's a snip of code to give you a idea of what I'm doing... namespace NatesKentuckyRook.Classes { public class RookCards : System.Collections.CollectionBase { // Constructors public RookCards() { } // Functions public void Reset() { List.Clear(); } public void AddCard(RookCard Card) { List.Add(Card); } } }
-
I created a collection class using the .NET help files, but when I add objects to the collection, it appears as though the each new object copies itself throughout the collection--all objects in the collection become equal to the new added object. Anyone run into this before? Here's a snip of code to give you a idea of what I'm doing... namespace NatesKentuckyRook.Classes { public class RookCards : System.Collections.CollectionBase { // Constructors public RookCards() { } // Functions public void Reset() { List.Clear(); } public void AddCard(RookCard Card) { List.Add(Card); } } }
Take a look at CollGen2 on GotDotNet. It will create a collection for you using the type you specify. As to your problem I've not seen it before. James Sonork: Hasaki "I left there in the morning with their God tucked underneath my arm their half-assed smiles and the book of rules. So I asked this God a question and by way of firm reply, He said - I'm not the kind you have to wind up on Sundays." "Wind Up" from Aqualung, Jethro Tull 1971
-
I created a collection class using the .NET help files, but when I add objects to the collection, it appears as though the each new object copies itself throughout the collection--all objects in the collection become equal to the new added object. Anyone run into this before? Here's a snip of code to give you a idea of what I'm doing... namespace NatesKentuckyRook.Classes { public class RookCards : System.Collections.CollectionBase { // Constructors public RookCards() { } // Functions public void Reset() { List.Clear(); } public void AddCard(RookCard Card) { List.Add(Card); } } }
There's nothing in the code you posted that would cause the problem you're describing. Can you post a sample app - especially the client code? Cheers, Tom Archer Author, Inside C#