|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Array of Value/Ref typeproblem referencing it. I have created a class Public Class Tags Private _Name As String Private _Address As String Public Sub New(ByVal Name As String, ByVal Address As String) _Name = Name _Address = Address End Sub Public Property Name() As String Get Return _Name End Get Set(ByVal Value As String) _Name = Value End Set End Property Public Property Address() As String Get Return _Address End Get Set(ByVal Value As String) _Address = Value End Set End Property End Class The question is how do I create and initialize an array to reference these objects. For instance I will populate the array myarray(x).Name = xxx, etc. Then update based on user inputs later. Thanks wg "wg" <w*@hotmail.com> schrieb Where are the value types in your example?> I am attempting to create an array of value types but seem to be > haveing a problem referencing it. Show quoteHide quote > I have created a class dim Tags(1) as tags> Public Class Tags > Private _Name As String > Private _Address As String > > Public Sub New(ByVal Name As String, ByVal Address As String) > _Name = Name > _Address = Address > End Sub > Public Property Name() As String > Get > Return _Name > End Get > Set(ByVal Value As String) > _Name = Value > End Set > End Property > Public Property Address() As String > Get > Return _Address > End Get > Set(ByVal Value As String) > _Address = Value > End Set > End Property > End Class > > The question is how do I create and initialize an array to reference > these objects. For instance I will populate the array > myarray(x).Name = xxx, etc. Then update based on user inputs later. tags(0) = new tags tags(1) = new tags tags(0).name = "name1" tags(1).name = "name2" Does this help? Armin >I am attempting to create an array of value types but seem to be haveing a I don't see any value types used in your code.>problem referencing it. >The question is how do I create and initialize an array to reference these Dim myarray(5) As Tags>objects. For instance I will populate the array myarray(x).Name = xxx, etc. myarray(2) = New Tags("John", "John's Address") myarray(2).Name = "xxx" Mattias -- Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com Please reply only to the newsgroup.
Show quote
Hide quote
"wg" <w*@hotmail.com> schrieb: \\\> I have created a class > Public Class Tags > Private _Name As String > Private _Address As String > > Public Sub New(ByVal Name As String, ByVal Address As String) > _Name = Name > _Address = Address > End Sub > Public Property Name() As String > Get > Return _Name > End Get > Set(ByVal Value As String) > _Name = Value > End Set > End Property > Public Property Address() As String > Get > Return _Address > End Get > Set(ByVal Value As String) > _Address = Value > End Set > End Property > End Class > > The question is how do I create and initialize an array to reference these > objects. For instance I will populate the array myarray(x).Name = xxx, > etc. Then update based on user inputs later. Dim a(9) As Tags For i As Integer = 0 To a.Length - 1 a(i) = New Tags() Next i .... a(i).Name = "Bla" /// Note that class types are reference types. When using a structure instead of the value type some additional code is necessary. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> Guess I am not sure the difference between a value type and a reference
type. But between the three replys I was able to get it to work. Thanks for the help. wg Show quoteHide quote "wg" <w*@hotmail.com> wrote in message news:Kvvwe.4074$ho.1813@bignews6.bellsouth.net... >I am attempting to create an array of value types but seem to be haveing a >problem referencing it. > > I have created a class > Public Class Tags > Private _Name As String > Private _Address As String > > Public Sub New(ByVal Name As String, ByVal Address As String) > _Name = Name > _Address = Address > End Sub > Public Property Name() As String > Get > Return _Name > End Get > Set(ByVal Value As String) > _Name = Value > End Set > End Property > Public Property Address() As String > Get > Return _Address > End Get > Set(ByVal Value As String) > _Address = Value > End Set > End Property > End Class > > The question is how do I create and initialize an array to reference these > objects. For instance I will populate the array myarray(x).Name = xxx, > etc. Then update based on user inputs later. > > Thanks > > wg > > |
|||||||||||||||||||||||