29-09-18, 08:12 AM
هذة تجربة سريعة ألق نظرة عليها : تم إستخدام الـ ( System.Collections.Generic.Dictionary )
وتستخدم بهذة الطريقة :
أتمنى تكون قريبة للي تفكر فية
هذا الكود : وضعت الصور لأني لا احب طريقة عرض الأكواد في المنتدى نهائياً
وتستخدم بهذة الطريقة :
أتمنى تكون قريبة للي تفكر فية
هذا الكود : وضعت الصور لأني لا احب طريقة عرض الأكواد في المنتدى نهائياً
كود :
Public Class viv
Private m_Fields As New Fields
Public ReadOnly Property Fields() As Fields
Get
Return Me.m_Fields
End Get
End Property
Public ReadOnly Property Fields(ByVal Name As String) As Field
Get
Return m_Fields(Name)
End Get
End Property
Public ReadOnly Property Values(ByVal Name As String) As Object
Get
Return m_Fields(Name).Value
End Get
End Property
End Class
Public Class Fields
Inherits System.Collections.Generic.Dictionary(Of String, Field)
Public Overloads Sub Add(ByVal NewField As Field)
MyBase.Add(NewField.Name, NewField)
End Sub
Public Overloads Function Add(ByVal Name As String, Value As Object) As Field
Dim Fld As New Field(Name, Value)
MyBase.Add(Name, Fld)
Return Fld
End Function
Public Overloads Function Add(ByVal Name As String) As Field
Dim Fld As New Field(Name, Nothing)
MyBase.Add(Name, Fld)
Return Fld
End Function
End Class
Public Class Field
Public Property Name As String
Public Property Value As Object
Public Sub New(ByVal Name As String, Value As Object)
Me.Name = Name
Me.Value = Value
End Sub
Public Overrides Function ToString() As String
Return Me.Name
End Function
End Classكود :
Public Class Form2
Dim MyFriendVIV As New viv
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Me.MyFriendVIV.Fields.Add("MyName", "Abulla")
Me.MyFriendVIV.Fields.Add("MyPhone", "555555")
Me.MyFriendVIV.Fields.Add("MyFriend", "viv")
Me.MyFriendVIV.Fields.Add("Salary").Value = 1200
Dim Fld As New Field("ID", 51)
Me.MyFriendVIV.Fields.Add(Fld)
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' Example 1
MsgBox(Me.MyFriendVIV.Fields("MyName").Value.ToString)
MsgBox(Me.MyFriendVIV.Fields("MyPhone").Value.ToString)
MsgBox(Me.MyFriendVIV.Fields("MyFriend").Value.ToString)
MsgBox(Me.MyFriendVIV.Fields("Salary").Value.ToString)
MsgBox(Me.MyFriendVIV.Fields("ID").Value.ToString)
' Example 2
MsgBox(Me.MyFriendVIV.Values("MyName"))
MsgBox(Me.MyFriendVIV.Values("MyPhone"))
MsgBox(Me.MyFriendVIV.Values("MyFriend"))
MsgBox(Me.MyFriendVIV.Values("Salary"))
MsgBox(Me.MyFriendVIV.Values("ID"))
End Sub
End Class