views:

302

answers:

2

I need two seperate lists, which every item is Integer, String, Bitmap - and one which every item is Integer, String String. However I don't know how to do this, or even where to look - I've googled for custom objects and custom object lists. What I'm trying to do is this. Custom Object1 is Integer, String, Bitmap Custom Object2 is Integer, String, String

In one thread I'll be adding items to List1(Of Object1), and processing them, and adding the results to List2(Of Object2), however I need to be able from other threads to look at the list and say only give me the items where Integer = (my thread ID), is this possible? Any help, or even links to information that would be relevant to this request would be helpful?

A: 
     Private Class Object1
        Public Property int() As Integer
            Get
                Return _int
            End Get
            Set(ByVal value As Integer)
                _int = value
            End Set
        End Property

        Public Property str() As String
            Get
                Return _str
            End Get
            Set(ByVal value As String)
                _str = value
            End Set
        End Property

        Public Property bmp() As Bitmap
            Get
                Return _bmp
            End Get
            Set(ByVal value As Bitmap)
                _bmp = value
            End Set
        End Property

        Friend _int As Integer
        Friend _str As String
        Friend _bmp As Bitmap

        Public Sub New(ByVal int As Integer, ByVal str As String, ByVal bmp as Bitmap)
            _int = int
            _str = str
            _bmp = bmp
        End Sub
    End Class 

Then you can initialize it like so...

Dim obj1 as List (Of Object1)
obj1.Add(New Object1(myInt, myStr, myBmp))
rockinthesixstring
You've declared all your public properties as dates
AUSteve
Good catch... unfortunately Copy/Paste is NOT always your friend.
rockinthesixstring
+1  A: 

Do something like this:

Public Class Type1
    Private _ThreadID As Integer
    Public Property ThreadID() As Integer
       Get
           Return _ThreadID
       End Get
       Set
           _ThreadID = Value
       End Set
    End Property

    Private _MyString As String
    Public Property MyString() as String
        Get
            Return _MyString
        End Get
        Set 
            _MyString = Value
        End Set
    End Property

    Private _MyBitmap As Bitmap
    Public Property MyBitmap As Bitmap
        Get
            Return _MyBitmap
        End Get
        Set
            _MyBitmap = Value
        End Set
    End Property
 End Class

.

Dim list1 As New List(Of Type1)()
''#  ... Add some items to the list...

''# List items with a given thread id:
Dim SomeThreadID As Integer = GetMyThreadID()
list1.Where(Function(o) o.ThreadID = SomeThreadID)

Of course, you'll want to use more meaningful names. As for the multi-threading aspect, look into using the Monitor class to lock your lists across all threads while one thread is using it.

Joel Coehoorn