Something like this:
Public Structure MyStruct
Public Item1 As Integer
Public Item2 As String
End Structure
Public Class StructList
Inherits ArrayList
Public Shadows Function Add(ByVal value As MyStruct) As Integer
Return MyBase.Add(value)
End Function
Default Public Shadows Property Item(ByVal index As Integer) As MyStruct
Get
Return CType(MyBase.Item(index), MyStruct)
End Get
Set(ByVal Value As MyStruct)
MyBase.Item(index) = Value
End Set
End Property
End Class
Private Sub Test( )
Dim myList As New StructList
Dim m_struct As MyStruct
m_struct.Item1 = 1
m_struct.Item2 = "test"
myList.Add(m_struct)
If myList(1).Item1 = 1 Then
Debug.WriteLine("found !")
End If
End Sub
This way you'll get a compile time error (with Option Strict On) both while
adding and while retrieving items that are not of type MyStruct.
hope that helps..
Imran.
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:91**********************************@microsof t.com...
sIs there anyway to Strongly type an arraylist. I have an arraylist where
object in the arraylist are of a type Structure, say "st" structure. I
would
like to reference elements of the structure in the arraylist where "ar" is
my
array list and "element 1 is an element in "st" like:
if ar(1).element1= xx then
so I don't have to use Ctype each time i want to get an element of the
arraylist structures.
--
Dennis in Houston