philprice Posted March 24, 2003 Posted March 24, 2003 Ive just been looking through the object browser and collections are a member of Microsoft.VisualBasic is there a system object that has the same methods (or similar etc) to the VB Collection object? Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
wyrd Posted March 24, 2003 Posted March 24, 2003 System.Collections System.Collections.Specialized :confused: Quote Gamer extraordinaire. Programmer wannabe.
*Experts* Nerseus Posted March 24, 2003 *Experts* Posted March 24, 2003 Try a Hashtable. -ner Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
philprice Posted March 25, 2003 Author Posted March 25, 2003 hashtables alow objects to be put into groups? Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
*Gurus* divil Posted March 25, 2003 *Gurus* Posted March 25, 2003 ArrayList is pretty much the most general-purpose collection class in the framework, I'd say. The HashTable is useful if you need a collection of name-value pairs. You are encouraged to inherit from CollectionBase to make your own strongly-typed collections :) Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
philprice Posted March 25, 2003 Author Posted March 25, 2003 divil, any thing on msdn / the webby for writing your own? Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
*Gurus* divil Posted March 25, 2003 *Gurus* Posted March 25, 2003 Sure - google for "inheriting from collectionbase" Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Experts* Nerseus Posted March 25, 2003 *Experts* Posted March 25, 2003 If you want an object that works like VB6's Collection, then a Hashtable is very similar, assuming you want to put objects in and retreive them by a Key. .NET supports many types of "collections", such as a Stack, a Queue, the ArrayList, Hashtable, and more. Plus, as divil mentioned, you can create your own collection objects that are type-safe. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
philprice Posted March 26, 2003 Author Posted March 26, 2003 I just want the a structure so i can do For each objectType in collection .. Next I'll look in to the options later on today. Thanks guys. Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
wyrd Posted March 26, 2003 Posted March 26, 2003 I just want the a structure so i can do For each objectType in collection .. Next I believe it's the IEnumberable interface which supports this, so anything that implements that interface supports for each. What I'm getting at, is that you can do a for each with a basic array, you don't need a collection. Quote Gamer extraordinaire. Programmer wannabe.
philprice Posted March 27, 2003 Author Posted March 27, 2003 But i want to use collections as the .add and .remove methods are really useful along with .count because i have a collection of classes with collections inside, i think with arrays you have to do needless group work just to add the functionalility you want, unless arrays are treaten as objects like they are in java... Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
wyrd Posted March 27, 2003 Posted March 27, 2003 Everything in .NET is an object. Look up the Array object in the object browser. Instead of Count, though, the property is Length. Also an Array is not dynamic either, so obviously there is no Add or Remove method. Use Array for a static list of elements, ArrayList for dynamic list. Quote Gamer extraordinaire. Programmer wannabe.
philprice Posted March 27, 2003 Author Posted March 27, 2003 okay im going to look into it in a mo. Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
*Experts* DiverDan Posted March 27, 2003 *Experts* Posted March 27, 2003 Here's an example of a static control array that Wyrd is refering to: Public Sub HideAllBorders() Dim ctr As Control Dim Border As Panel For Each ctr In Me.grpConversionTypes.Controls If TypeOf ctr Is Panel Then For Each Border In Borders Border.Visible = False Next End If Next End Sub Where Borders is the control array. Quote Member, in good standing, of the elite fraternity of mentally challenged programmers. Dolphins Software
wyrd Posted March 27, 2003 Posted March 27, 2003 Actually I was just talking about regular old Arrays.. char[] someString = new char[50]; That's a static array object *shrug* ..since you mentioned it.. :) Aren't control arrays dynamic? You can add/remove controls from control arrays right? On a side note, good example.. I forgot about control arrays and how you can loop through those too, etc. Heh. Quote Gamer extraordinaire. Programmer wannabe.
*Gurus* Derek Stone Posted March 28, 2003 *Gurus* Posted March 28, 2003 Controls belong to a Control.ControlCollection collection, which is nothing more than a strongly typed collection that, as required, implements ICollection, IEnumerable, IList and ICloneable (I believe). Quote Posting Guidelines
philprice Posted March 28, 2003 Author Posted March 28, 2003 Okay ive done it with Inheriting CollectionBase, and it works nicely :), just one question, you have to overload onSet() etc, which is no problem, but you need to compare the type and thorw and error if it doesnt match, this again is okay, but the only way i could nicely get the type is.. Private story As New RSSStory Private storyType As Type = Type.GetTypeFromHandle(Type.GetTypeHandle(story)) Which is okay, but im sure there is a better way of doing it?? Quote Phil Price� Visual Studio .NET 2003 Enterprise Edition Microsoft Student Partner 2004 Microsoft Redmond, EMEA Intern 2004
*Gurus* divil Posted March 29, 2003 *Gurus* Posted March 29, 2003 How about story.GetType() ? Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
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.