2

我需要两个单独的列表,每个项目都是整数、字符串、位图 - 并且每个项目都是整数、字符串字符串。但是我不知道该怎么做,甚至不知道去哪里找——我已经用谷歌搜索了自定义对象和自定义对象列表。我想做的是这个。自定义 Object1 为整数、字符串、位图 自定义 Object2 为整数、字符串、字符串

在一个线程中,我将向 List1(Of Object1) 添加项目,并对其进行处理,并将结果添加到 List2(Of Object2),但是我需要能够从其他线程查看列表并说只给我Integer = (我的线程 ID) 的项目,这可能吗?任何帮助,甚至与此请求相关的信息链接都会有所帮助吗?

4

2 回答 2

3

做这样的事情:

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)

当然,您会想要使用更有意义的名称。至于多线程方面,请考虑使用Monitor该类在一个线程使用它时跨所有线程锁定列表。

于 2010-01-24T04:35:28.063 回答
0
     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 

然后你可以像这样初始化它......

Dim obj1 as List (Of Object1)
obj1.Add(New Object1(myInt, myStr, myBmp))
于 2010-01-24T04:30:34.750 回答