Hi,
why do you think a structure would be messy? I wouldn't expect it to be any more (or less) messy than a class, if you are storing numbers a structure would probably be more appropriate too.
J
Main Topics
Browse All TopicsI want to store 3 related numbers in vb.net silverlight.
Anyway I am not sure whther to use a class or structure . a structure is messy to use in .net
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
What you use really depends on what you want to do with the data. If you just want to store and retrieve them, I would say use a structure. If you want to run processing methods on the the numbers then I would use a class. Like Babycorn said, there is no reason a structure is messy in .net. I use them all the time.
You know actually, Structures are a "lightweight class type", given that structures provide a way to define a type that supports encapsulation but cannot be used to build a heirarchy of related types (as structures are implicitily sealed, which means you cannot derive a structure from another structure). When you need to build a family of related types through inheritance, then you will need to make use of class types.
Structures can define constructors, can implement interfaces, and can contain any number of properties, methods, events, and overloaded operators.
Observe how the following Structure and Class are identical:
Here's an example of a Structure that stores 3 related numbers:
Public Structure MyNumbersStructure
'Create a constructor that takes 3
' numbers as arguments
Public Sub New(ByVal no1 As Integer, _
ByVal no2 As Integer, _
ByVal no3 As Integer)
Number1 = no1
Number2 = no2
Number3 = no3
End Sub
Private mNumber1 As Integer
Public Property Number1() As Integer
Get
Return mNumber1
End Get
Set(ByVal value As Integer)
mNumber1 = value
End Set
End Property
Private mNumber2 As Integer
Public Property Number2() As Integer
Get
Return mNumber2
End Get
Set(ByVal value As Integer)
mNumber2 = value
End Set
End Property
Private mNumber3 As Integer
Public Property Number3() As Integer
Get
Return mNumber3
End Get
Set(ByVal value As Integer)
mNumber3 = value
End Set
End Property
'Override the ToString Function
Public Overrides Function ToString() As String
Return String.Format("[Number1: {0}; Number2: {1}; Number3: {2}]", _
Number1, Number2, Number3)
End Function
End Structure
Here's an example of a Class that stores 3 related numbers:
Public Class MyNumbersClass
'Create a constructor that takes 3
' numbers as arguments
Public Sub New(ByVal no1 As Integer, _
ByVal no2 As Integer, _
ByVal no3 As Integer)
Number1 = no1
Number2 = no2
Number3 = no3
End Sub
Private mNumber1 As Integer
Public Property Number1() As Integer
Get
Return mNumber1
End Get
Set(ByVal value As Integer)
mNumber1 = value
End Set
End Property
Private mNumber2 As Integer
Public Property Number2() As Integer
Get
Return mNumber2
End Get
Set(ByVal value As Integer)
mNumber2 = value
End Set
End Property
Private mNumber3 As Integer
Public Property Number3() As Integer
Get
Return mNumber3
End Get
Set(ByVal value As Integer)
mNumber3 = value
End Set
End Property
'Override the ToString Function
Public Overrides Function ToString() As String
Return String.Format("[Number1: {0}; Number2: {1}; Number3: {2}]", _
Number1, Number2, Number3)
End Function
End Class
Hey CodeCruiser! Yes, finally getting in on a few. :) I've been really busy redesigning our website. I'm doing it in Silverlight 3, which is awesome! I'm new to it, but having a blast. I'm also working on an internal windows based sql server database application, which is one of those on-going things, and maintaining. Hope you've been well, and winning lots!
I think the biggest difference is that a Class is a Reference Type while a Structure is a Value Type.
This comes into play when you start passing them around:
http://msdn.microsoft.com/
When you pass a Class ByVal you can change the items in the parameter.
When you pass a Structure ByVal a COPY is made and changes to the items are only local.
When you pass a Class ByRef you can change the INSTANCE the original variable points to.
When you pass a Structure ByVal you can change the items in the original variable.
Summed up in the Table from the link:
Not to mention that the storage location is different.And... Take a look here; http://www.jaggersoft.com/
David
Business Accounts
Answer for Membership
by: aiklamhaPosted on 2009-10-27 at 03:55:29ID: 25670881
it depends on how you want to work on those numbers.. ....