Hi, I have a little understanding of List(of), Dictionary and Arrays, but with all the alternatives, I'm struggling to understand the best for my application. I have a number objects, not more than a couple of hundred, each has a name, a dimension (height x width), a type (one of five) and a colour. I need to be able to temporarily store them, and retrieve just one of them based on any or all of the values. Please could you advise on the best choice and perhaps with a simple example? I haven't added code I've tried as Dictionary didn't work, no key, List(of) didn't allow me different types and arrays seem like such an overkill. Many thanks in advance.
What I have tried:
Public Class Products
Public Property Name As String
Public Property Width As Integer
Public Property Height As Integer
Public Property Type As String
Public Property Colour_Class As String
Public Property Bool_Class As Boolean
'Temporay values that I can access from another class
Public Shared Name_Temp As String
Public Shared Width_Temp As Integer
Public Shared Height_Temp As Integer
Public Shared Type_Temp As String
Public Shared Color_Class_Temp As String
Public Shared Bool_Class_Temp As Boolean
Dim New_Products As New List(Of Products)
Public Sub DoStuff()
'Add individual Products to New_Products
New_Products.Add(New Products With {.Name = "John", .Width = 222, .Height = 111, .Type = "metal", .Colour_Class = "Yellow", .Bool_Class = True})
New_Products.Add(New Products With {.Name = "Fred", .Width = 100, .Height = 654, .Type = "plastic", .Colour_Class = "green", .Bool_Class = False})
New_Products.Add(New Products With {.Name = "Harry", .Width = 555, .Height = 123, .Type = "wood", .Colour_Class = "blue", .Bool_Class = True})
New_Products.Add(New Products With {.Name = "Jill", .Width = 333, .Height = 200, .Type = "cotton", .Colour_Class = "red", .Bool_Class = False})
'Get individual values from product named John
For Each Product In New_Products
With Product
If Product.Name = "John" Then
Name_Temp = .Name
Width_Temp = .Width.ToString
Type_Temp = .Type
End If
End With
Next
'Remove product where width = 100
For i As Integer = 1 To New_Products.Count - 1
If New_Products(i).Width = 100 Then
New_Products.RemoveAt(1)
End If
Next i
End Sub
End Class