اريد اضافة قائمة فى
كود :
Public Shared testlist As New Dictionary(Of String, String)
لاكن المشكلة ان هذا الكود لايقبل الى قيمتيآ
كود :
BannedList.Add("vb4arb1", "vb4arb2")
هل يمكن جعلة يقبل 6 قيم ام هذا مستحيل ؟
السلام عليكم
ليس مستحيل، ولكن تحتاج طريقة مختلفة قليلا عن العادة،
احدى الطريق وهي أن تجعل القيمة الثانية مصفوفة مثل هذا الكود
كود :
Public Shared testlist As New Dictionary(Of String, String())
ولإضافة البيانات لها مثل هذا الكود
كود :
testlist.Add("a", New String() {"a1", "a2", "a3", "a4", "a5", "a6"})
testlist.Add("b", New String() {"b1", "b2", "b3", "b4", "b5", "b6"})
testlist.Add("c", New String() {"c1", "c2", "c3", "c4", "c5", "c6"})
ولقراءة البيانات مثل هذا الكود
كود :
MsgBox(testlist("b")(0))
MsgBox(testlist("b")(1))
MsgBox(testlist("b")(2))
MsgBox(testlist("b")(3))
أو
كود :
Dim v() As String = testlist.Item("b")
MsgBox(v(0))
MsgBox(v(1))
MsgBox(v(2))
وهذه طريقة أخرى باستخدام كلاس للحقول مثل هذا الكود
كود :
Private testlist As New List(Of test)
Class test
Property ID As String
Property Username As String
Property Key As String
Property Key2 As String
Property JoinDate As String
Property LeftDate As String
Property Zone As String
End Class
ولإضافة البيانات لها مثل هذا الكود
كود :
testlist.Add(New test With {
.ID = "1", .Username = "vb4arb0",
.Key = "556", .Key2 = "101",
.JoinDate = "2017/10/02 14:37:24",
.LeftDate = "2017/10/02 15:37:24",
.Zone = "0"}
)
ولقراءة البيانات مثل هذا الكود
كود :
MsgBox(testlist(0).ID)
MsgBox(testlist(0).Username)
أو
كود :
Dim tst As test = testlist(0)
MsgBox(tst.ID)
MsgBox(tst.Username)
وفي حالة البحث واظهار النتيجة مثل هذا الكود
كود :
Dim tst = testlist.Where(Function(t) t.ID = 1).FirstOrDefault
If tst IsNot Nothing Then
MsgBox(tst.JoinDate)
MsgBox(tst.LeftDate)
Else
MsgBox("لا يوجد")
End If