Domanda

Ho bisogno di due liste separate, che ogni elemento è Integer, String, Bitmap - e uno che ogni elemento è Integer, String String. Comunque io non so come fare questo, o anche dove cercare - Googled per gli oggetti personalizzati e le liste di oggetti personalizzati. Quello che sto cercando di fare è questo. Personalizzato Object1 è Integer, String, Bitmap Personalizzato Object2 è Integer, String, String

In un thread sarò l'aggiunta di elementi a List1 (Of Object1), e il loro trattamento, e sommando i risultati di List2 (Of Object2), però ho bisogno di essere in grado da altri thread a guardare la lista e dire solo darmi gli elementi in cui Integer = (il mio ID filo), è possibile? Qualsiasi aiuto, o anche i collegamenti alle informazioni che potrebbero essere rilevanti per tale richiesta sarebbe utile?

È stato utile?

Soluzione

fare qualcosa di simile:

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)

Naturalmente, ti consigliamo di utilizzare nomi più significativi. Per quanto riguarda l'aspetto multi-threading, considerare di usare la classe Monitor per bloccare le vostre liste in tutte le discussioni, mentre un thread sta utilizzando.

Altri suggerimenti

     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 

Quindi è possibile inizializzare in questo modo ...

Dim obj1 as List (Of Object1)
obj1.Add(New Object1(myInt, myStr, myBmp))
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top