我需要两个单独列表,其中每一个项目是整数,字符串,位图 - 和一个其中每一个项目是整数,字符串的字符串。但是我不知道如何做到这一点,甚至在哪里看 - 我GOOGLE了自定义对象和自定义对象名单。我想要做的就是这个。 自Object1是整数,字符串,位图 定制Object2的是整数,字符串,字符串

在一个线程我会增加项目列表1(中Object1),并处理它们,并把结果加入列表2(共对象2),但我需要能够从其他线程查看列表和发言权只给我的项目,其中整数=(我的线程ID),这可能吗?任何帮助,甚至是信息的链接,这将是有关这个请求将是有益的?

有帮助吗?

解决方案

做这样的事情:

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类当一个线程是用它来锁定所有线程的列表。

其他提示

     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))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top