By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,640 Members | 1,331 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,640 IT Pros & Developers. It's quick & easy.

Simple Class Problem - Array as property.

P: n/a
How do I pass an array of values as a property of a class?
i.e. If Class1 has a property called XVals how do I assign an array of
x-values (X()) to the XVals property of Class 1? I need an example of the
property set procedure, please.
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Keith,

something like this?

Public Class Something

Dim mySingle As Single() = {123, 234, 345}

Public Property XYals() As Single()
Get
Return mySingle
End Get
Set(ByVal Value As Single())
mySingle = Value
End Set
End Property

End Class

Klaus

"Keith Rebello" <kr**@gecinc.com> schrieb im Newsbeitrag
news:Fb******************@dfw-read.news.verio.net...
How do I pass an array of values as a property of a class?
i.e. If Class1 has a property called XVals how do I assign an array of
x-values (X()) to the XVals property of Class 1? I need an example of the
property set procedure, please.

Nov 20 '05 #2

P: n/a
Keith,
Have you tried something like:

Public Class Class1

Private m_xvals() As Integer

Public Property XVals() As Integer()
Get
Return m_xvals
End Get
Set(ByVal value As Integer())
m_xvals = value
End Set
End Property

Public Shared Sub Main()
Dim c1 As New Class1
Dim x() As Integer = {0, 1, 2, 3, 4, 5}

c1.XVals = x

c1.XVals = New Integer() {3, 4, 5}

End Sub

End Class

In the above I am replacing the existing array each time, alternatively
could use Array.CopyTo to keep the same m_xvals array, but replace its
values. (to avoid aliasing problems)

Set(ByVal value As Integer())
value.CopyTo(m_xvals, 0)
End Set

Of course with CopyTo, you need to be certain that m_xvals is the correct
size.

Hope this helps
Jay

"Keith Rebello" <kr**@gecinc.com> wrote in message
news:Fb******************@dfw-read.news.verio.net...
How do I pass an array of values as a property of a class?
i.e. If Class1 has a property called XVals how do I assign an array of
x-values (X()) to the XVals property of Class 1? I need an example of the
property set procedure, please.

Nov 20 '05 #3

P: n/a
Thanks a lot, Jay and Klaus. That takes care of my problem.

"Keith Rebello" <kr**@gecinc.com> wrote in message
news:Fb******************@dfw-read.news.verio.net...
How do I pass an array of values as a property of a class?
i.e. If Class1 has a property called XVals how do I assign an array of
x-values (X()) to the XVals property of Class 1? I need an example of the
property set procedure, please.

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.