PC Review
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
The old Structure/Class Argument
Forums
Newsgroups
Microsoft DotNet
Microsoft VB .NET
The old Structure/Class Argument
![]() |
The old Structure/Class Argument |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
I recently wrote a VB.NET application using VS2005. I needed to be able
to build linked lists in memory of items that were represented by a group of variables. For example, Friend Structure foo Dim var1 As String Dim var2 As Integer Dim var3 As Boolean End Structure I needed several structures, each with a different mix of number of members and the datatypes. Now, these structures could have been implemented as classes. But I do not know how multiple instances of a class can be linked together so I can process them in a standard For Each/Next loop. I see one guideline of whether to use a Class or a Structure is if the Structure is less or equal to 16 bytes. Several of these structures will be larger than that, so I am open to converting the code to use classes instead of structures if someone can give me some pointers on how to link instances of a class together. TIA, |
|
|
|
#2 |
|
Guest
Posts: n/a
|
Use a collection
Tom zacks@construction-imaging.com wrote: >I recently wrote a VB.NET application using VS2005. I needed to be able >to build linked lists in memory of items that were represented by a >group of variables. For example, > >Friend Structure foo > Dim var1 As String > Dim var2 As Integer > Dim var3 As Boolean >End Structure > >I needed several structures, each with a different mix of number of >members and the datatypes. Now, these structures could have been >implemented as classes. But I do not know how multiple instances of a >class can be linked together so I can process them in a standard For >Each/Next loop. > >I see one guideline of whether to use a Class or a Structure is if the >Structure is less or equal to 16 bytes. Several of these structures >will be larger than that, so I am open to converting the code to use >classes instead of structures if someone can give me some pointers on >how to link instances of a class together. > >TIA, > > > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Well if i see your structure i would say just leave it as a structure as it would only hurt the performance of your app to convert this to a class Basically, classes are reference types and structs are value types. Reference types get stored differently than value types. Value types are stored more efficiently on the stack vs classes on the heap using structures will also save the GC some trips :-) as it does not need to reclaim memory want to know in detail when to use a class or when to use a structure ??? watch this video http://msdn.microsoft.com/netframew...richtypesystem/ regards Michel Posseth [MCP] <zacks@construction-imaging.com> schreef in bericht news:1137167240.183905.106040@o13g2000cwo.googlegroups.com... >I recently wrote a VB.NET application using VS2005. I needed to be able > to build linked lists in memory of items that were represented by a > group of variables. For example, > > Friend Structure foo > Dim var1 As String > Dim var2 As Integer > Dim var3 As Boolean > End Structure > > I needed several structures, each with a different mix of number of > members and the datatypes. Now, these structures could have been > implemented as classes. But I do not know how multiple instances of a > class can be linked together so I can process them in a standard For > Each/Next loop. > > I see one guideline of whether to use a Class or a Structure is if the > Structure is less or equal to 16 bytes. Several of these structures > will be larger than that, so I am open to converting the code to use > classes instead of structures if someone can give me some pointers on > how to link instances of a class together. > > TIA, > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
I am. A collection of structures.
Sorry, I forgot to mention that. I would prefer to use multiple instances of a class to emulate a collection but I can't figure out how to link the multiple instances. |
|
|
|
#5 |
|
Guest
Posts: n/a
|
Zacks,
I assume that you a List wants of those. http://msdn2.microsoft.com/en-us/library/6sh2ey19(en-us,VS.80).aspx Although that I never use a structure and would use a class \\\ Friend Structure foo Dim var1 As String Dim var2 As Integer Dim var3 As Boolean End Structure Private mylist As New List(Of foo) /// I hope this helps, Cor |
|
|
|
#6 |
|
Guest
Posts: n/a
|
Is a List better than a Collection?
You mention that you would use a class, but in your example code you used a structure. Can you: Class foo <define each member of the former structure as a property> End Structure Private mylist As New List(Of foo) (Thanks for the pointer to the new List class, anyway. I will research it) |
|
|
|
#7 |
|
Guest
Posts: n/a
|
>
> You mention that you would use a class, but in your example code you > used a structure. (To integrate your sample) Can you: > > Class foo > <define each member of the former structure as a property> > End Structure > Private mylist As New List(Of foo) > > (Thanks for the pointer to the new List class, anyway. I will research > it) Yes, Yes (however not end structure but end class) see the link I gave there is very much information. I hope this helps, Cor |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

