|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Creating Collections in ClassesIn: microsoft.public.dotnet.framework.performance
Hi, can someone give links either in msdn.microsoft.com or other sites that tell me what are the best ways to create Collection properties in a class written in Visual Basic.NET? Eg., say I create a Class that instantiated allows you to get a property of collections: Forms.Controls, TreeView.Nodes etc etc. In my work, I only used ArrayList to create Collections but want to try other interface classes such iCollection, hasttables, etc etc. Thanks in advance. You have to inherit from one of the collection classes you mention, and
override the methods you want... I don't know where to get a sample of this, since I'm not in my computer right now, but there's a sample in "101 VB.Net Samples" (if you can google it). Here's a sample (of course, I haven't compiled it, and it will not run unless you complete it, but it gives you an idea): Public Class MyClass '...Properties and Methods... Public sub New () 'TODO:assign default values End Sub Public Sub New (PropA as Integer, PropB as Integer) 'TODO:assign values to the new object End Sub Public Property MyPropA () as Integer 'TODO:Inner implementation of the property End Property Public Property MyPropB () as String 'TODO:Inner implementation of the property End Property End Class Public Class MyCollection Inherits Hashtable '(for example) Public Overrides Overloads Sub Add (key as Object, o as object) MyBase.Add(key, o) End Sub Public Overloads Sub Add (key as Object, PropA as Integer, PropB as String) Mybase.Add(key, new MyClass(PropA, PropB)) End Sub 'etc... End Class If you need a wider sample, contact me (to my e-mail) and I'll send you a sample when I get home. Hope this helps. VBen. Show quoteHide quote "Anonymous" <Anonym***@discussions.microsoft.com> escribió en el mensaje news:164889E6-54D4-4801-B777-4D84EF746500@microsoft.com... > In: microsoft.public.dotnet.framework.performance > Hi, can someone give links either in msdn.microsoft.com or other sites that > tell me what are the best ways to create Collection properties in a class > written in Visual Basic.NET? > > Eg., say I create a Class that instantiated allows you to get a property of > collections: Forms.Controls, TreeView.Nodes etc etc. > > In my work, I only used ArrayList to create Collections but want to try > other interface classes such iCollection, hasttables, etc etc. > > Thanks in advance. Hi, VBen. Thanks a lot for your sample. That's great code.
Is there a site that describes fully the pros and cons of using which Collection class, etc? I remember there were articles in msdn.microsoft.com about this matter (it also include performance issues of these classes; eg., you should not use inherit the iComparable class if your class barely use sorts since iComparable is an unnecessary resource hog, etc.) Thanks. Show quoteHide quote "VBen" wrote: > You have to inherit from one of the collection classes you mention, and > override the methods you want... I don't know where to get a sample of this, > since I'm not in my computer right now, but there's a sample in "101 VB.Net > Samples" (if you can google it). > Here's a sample (of course, I haven't compiled it, and it will not run > unless you complete it, but it gives you an idea): > > Public Class MyClass > '...Properties and Methods... > Public sub New () > 'TODO:assign default values > End Sub > Public Sub New (PropA as Integer, PropB as Integer) > 'TODO:assign values to the new object > End Sub > Public Property MyPropA () as Integer > 'TODO:Inner implementation of the property > End Property > Public Property MyPropB () as String > 'TODO:Inner implementation of the property > End Property > End Class > Public Class MyCollection > Inherits Hashtable '(for example) > Public Overrides Overloads Sub Add (key as Object, o as object) > MyBase.Add(key, o) > End Sub > Public Overloads Sub Add (key as Object, PropA as Integer, PropB as > String) > Mybase.Add(key, new MyClass(PropA, PropB)) > End Sub > 'etc... > End Class > > If you need a wider sample, contact me (to my e-mail) and I'll send you a > sample when I get home. > Hope this helps. > VBen. > > "Anonymous" <Anonym***@discussions.microsoft.com> escribió en el mensaje > news:164889E6-54D4-4801-B777-4D84EF746500@microsoft.com... > > In: microsoft.public.dotnet.framework.performance > > Hi, can someone give links either in msdn.microsoft.com or other sites > that > > tell me what are the best ways to create Collection properties in a class > > written in Visual Basic.NET? > > > > Eg., say I create a Class that instantiated allows you to get a property > of > > collections: Forms.Controls, TreeView.Nodes etc etc. > > > > In my work, I only used ArrayList to create Collections but want to try > > other interface classes such iCollection, hasttables, etc etc. > > > > Thanks in advance. > > > I'm not aware of any site, besides MSDN. (msdn.microsoft.com or
www.msdn.com) If you find any, please let me know, since I work with collections a lot, inherited ones, and would like to be able to take a more accurate decission in which base collection class to use... Thank you. VBen. "Anonymous" <Anonym***@discussions.microsoft.com> escribió en el mensaje msdn.microsoft.comnews:0DF7A55F-2B41-4BA0-BA51-2DE1AE734B88@microsoft.com... > Hi, VBen. Thanks a lot for your sample. That's great code. > > Is there a site that describes fully the pros and cons of using which > Collection class, etc? I remember there were articles in Show quoteHide quote > about this matter (it also include performance issues of these classes; eg., > you should not use inherit the iComparable class if your class barely use > sorts since iComparable is an unnecessary resource hog, etc.) > > Thanks. > > > "VBen" wrote: > > > You have to inherit from one of the collection classes you mention, and > > override the methods you want... I don't know where to get a sample of this, > > since I'm not in my computer right now, but there's a sample in "101 VB.Net > > Samples" (if you can google it). > > Here's a sample (of course, I haven't compiled it, and it will not run > > unless you complete it, but it gives you an idea): > > > > Public Class MyClass > > '...Properties and Methods... > > Public sub New () > > 'TODO:assign default values > > End Sub > > Public Sub New (PropA as Integer, PropB as Integer) > > 'TODO:assign values to the new object > > End Sub > > Public Property MyPropA () as Integer > > 'TODO:Inner implementation of the property > > End Property > > Public Property MyPropB () as String > > 'TODO:Inner implementation of the property > > End Property > > End Class > > Public Class MyCollection > > Inherits Hashtable '(for example) > > Public Overrides Overloads Sub Add (key as Object, o as object) > > MyBase.Add(key, o) > > End Sub > > Public Overloads Sub Add (key as Object, PropA as Integer, PropB as > > String) > > Mybase.Add(key, new MyClass(PropA, PropB)) > > End Sub > > 'etc... > > End Class > > > > If you need a wider sample, contact me (to my e-mail) and I'll send you a > > sample when I get home. > > Hope this helps. > > VBen. > > > > "Anonymous" <Anonym***@discussions.microsoft.com> escribió en el mensaje > > news:164889E6-54D4-4801-B777-4D84EF746500@microsoft.com... > > > In: microsoft.public.dotnet.framework.performance > > > Hi, can someone give links either in msdn.microsoft.com or other sites > > that > > > tell me what are the best ways to create Collection properties in a class > > > written in Visual Basic.NET? > > > > > > Eg., say I create a Class that instantiated allows you to get a property > > of > > > collections: Forms.Controls, TreeView.Nodes etc etc. > > > > > > In my work, I only used ArrayList to create Collections but want to try > > > other interface classes such iCollection, hasttables, etc etc. > > > > > > Thanks in advance. > > > > > > Hi, Ben. Can't believe this but it took me a long time to find the link I
mentioned in MSDN site! Here it is: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconcreatingmanipulatingcollectionobjects.asp Here's another excellent site on the same topic: http://www.informit.com/guides/content.asp?g=dotnet&seqNum=120 Show quoteHide quote "VBen" wrote: > I'm not aware of any site, besides MSDN. (msdn.microsoft.com or > www.msdn.com) > If you find any, please let me know, since I work with collections a lot, > inherited ones, and would like to be able to take a more accurate decission > in which base collection class to use... > Thank you. > VBen. > > "Anonymous" <Anonym***@discussions.microsoft.com> escribió en el mensaje > news:0DF7A55F-2B41-4BA0-BA51-2DE1AE734B88@microsoft.com... > > Hi, VBen. Thanks a lot for your sample. That's great code. > > > > Is there a site that describes fully the pros and cons of using which > > Collection class, etc? I remember there were articles in > msdn.microsoft.com > > about this matter (it also include performance issues of these classes; > eg., > > you should not use inherit the iComparable class if your class barely use > > sorts since iComparable is an unnecessary resource hog, etc.) > > > > Thanks. > > > > > > "VBen" wrote: > > > > > You have to inherit from one of the collection classes you mention, and > > > override the methods you want... I don't know where to get a sample of > this, > > > since I'm not in my computer right now, but there's a sample in "101 > VB.Net > > > Samples" (if you can google it). > > > Here's a sample (of course, I haven't compiled it, and it will not run > > > unless you complete it, but it gives you an idea): > > > > > > Public Class MyClass > > > '...Properties and Methods... > > > Public sub New () > > > 'TODO:assign default values > > > End Sub > > > Public Sub New (PropA as Integer, PropB as Integer) > > > 'TODO:assign values to the new object > > > End Sub > > > Public Property MyPropA () as Integer > > > 'TODO:Inner implementation of the property > > > End Property > > > Public Property MyPropB () as String > > > 'TODO:Inner implementation of the property > > > End Property > > > End Class > > > Public Class MyCollection > > > Inherits Hashtable '(for example) > > > Public Overrides Overloads Sub Add (key as Object, o as object) > > > MyBase.Add(key, o) > > > End Sub > > > Public Overloads Sub Add (key as Object, PropA as Integer, PropB as > > > String) > > > Mybase.Add(key, new MyClass(PropA, PropB)) > > > End Sub > > > 'etc... > > > End Class > > > > > > If you need a wider sample, contact me (to my e-mail) and I'll send you > a > > > sample when I get home. > > > Hope this helps. > > > VBen. > > > > > > "Anonymous" <Anonym***@discussions.microsoft.com> escribió en el mensaje > > > news:164889E6-54D4-4801-B777-4D84EF746500@microsoft.com... > > > > In: microsoft.public.dotnet.framework.performance > > > > Hi, can someone give links either in msdn.microsoft.com or other sites > > > that > > > > tell me what are the best ways to create Collection properties in a > class > > > > written in Visual Basic.NET? > > > > > > > > Eg., say I create a Class that instantiated allows you to get a > property > > > of > > > > collections: Forms.Controls, TreeView.Nodes etc etc. > > > > > > > > In my work, I only used ArrayList to create Collections but want to > try > > > > other interface classes such iCollection, hasttables, etc etc. > > > > > > > > Thanks in advance. > > > > > > > > > > > >
Other interesting topics
How to assign value to Excel 2000 worksheet cell
Simple: Excel Jet 4.0 Link vb 2005 Microsoft: Help with OLE documents... How to Deserialize to a specific object instance. ENTER and forms Method for finding dotnet version How does IIS or Framework set the Content-Length header ? Excel process doesn't shut down xcel error at web server VS 2002 and Framework 1.0/1.1 SP upgrades |
|||||||||||||||||||||||