How to create your own type and use it to store data
class, dictionary, types, vb.net
Solution
The basic definition of a `Dictionary` is given by `Dictionary(Of type1, type2)`, where types can be anything, that is, primitive types (`String`, `Double`, etc.) or ones you create (via `Class`, for example). Also you can account for them as "individual variables" or inside collections (`Lists`, `Arrays`, etc.). Some examples:
Dim dict = New Dictionary(Of String, List(Of String))
Dim tempList = New List(Of String)
tempList.Add("val11")
tempList.Add("val12")
tempList.Add("val13")
dict.Add("1", tempList)
Dim dict2 = New Dictionary(Of String, type2)
Dim tempProp = New type2
With tempProp
.prop1 = "11"
.prop2 = "12"
.prop2 = "13"
End With
dict2.Add("1", tempProp)
Dim dict3 = New Dictionary(Of String, List(Of type2))
Dim tempPropList = New List(Of type2)
Dim tempProp2 = New type2
With tempProp2
.prop1 = "11"
.prop2 = "12"
.prop2 = "13"
End With
tempPropList.Add(tempProp2)
dict3.Add("1", tempPropList)
Where `type2` is defined by the following Class:
Public Class type2
Public prop1 As String
Public prop2 As String
Public prop3 As String
End Class
NOTE: you can change the types in the examples above as much as you wish; also put anything (List, custom types, etc.) in both `Values` and `Keys`.
NOTE2: the primitive types in VB.NET (for example: `Double`) are basically a bunch of variables (declared globally inside the given framework) and functions: `Double.IsInfinity` (function), `Double.MaxValue` (variable), etc.; thus a type can be understood as an in-built Class, that is, a general name for a group of functions and variables, which can be used to define another variable in a different Class. I think that the proposed example is pretty descriptive.
Problem
I've recently ran into the problem that dictionary only allows 1 value per key. Reading around I have seen multiple answers suggesting creating a type through a classes. Now granted I don't know much about classes, I have always though that classes were just a collection of functions and subs. How come they can create data types and how do you use them to do so?