تقييم الموضوع :
  • 0 أصوات - بمعدل 0
  • 1
  • 2
  • 3
  • 4
  • 5
Collection & DataBase Part 1
#2
الكود التالي يوضح شكل الكلاس كاملا و في المشاركات التالية سنوضح كيفية اضافة صفات و طرق اخري للكلاس بل وسنضيف له دوال تجعل من الممكن استخدامه في برامج الداتا بيز التقليدية


كود :
Public Class VB4ArabStringCollection
   Implements ICloneable, IEnumerable

#Region " Field "

   ' define internal list which will work as store for the collection Data
   ' benifits to use arraylist because it supports sort , binarysearch, ... and so on
   ' for more information about ArrayList, please visit the below link
   ' https://msdn.microsoft.com/en-us/library/System.Collections.ArrayList_methods%28v=vs.110%29.aspx
   Private list As ArrayList

#End Region

#Region " Constructor "

   Public Sub New()
       ' initialize the internal list
       Me.list = New ArrayList()
   End Sub

   Public Sub New(ByVal capacity As Integer)
       ' initialize the internal list with a defined capacity
       Me.list = New ArrayList(capacity)
   End Sub

#End Region

#Region " Property "

   Public ReadOnly Property InnerList As ArrayList
       Get
           If (Me.list Is Nothing) Then
               Me.list = New ArrayList
           End If
           Return Me.list
       End Get
   End Property

#End Region

#Region " Methods "

   ' used to add items to the collection
   Public Sub Add(item As String)
       Me.InnerList.Add(item)
   End Sub

   ' used to remove items from the collection
   Public Sub Remove(item As String)
       Me.InnerList.Remove(item)
   End Sub

   ' Clone/copy the collection
   Public Function Clone() As Object Implements ICloneable.Clone
       ' define new empty VB4ArabStringCollection
       Dim stringCol As VB4ArabStringCollection = New VB4ArabStringCollection
       ' add all items to the collection
       For Each item As Object In Me
           ' Option 1 add items as object
           stringCol.InnerList.Add(item.Clone())

           '' Option 2 add item as string
           'Dim str As String = CType(item, String)
           'stringCol.InnerList.Add(str)

       Next
       Return stringCol
   End Function

   ' Returns an instance of class VB4ArabStringCollectionEnumerator
   Public Function GetEnumerator() As IEnumerator Implements IEnumerable.GetEnumerator
       Return New VB4ArabStringCollectionEnumerator(Me)
   End Function

#End Region

#Region " Internal Enumerator "

   Private Class VB4ArabStringCollectionEnumerator
       Implements IEnumerator

       Private location As Integer = -1
       Private vb4ArabCollection As VB4ArabStringCollection

       Public Sub New(stringCol As VB4ArabStringCollection)
           Me.vb4ArabCollection = stringCol
       End Sub

       ' Current retrieves current item from the collection.
       Public ReadOnly Property Current As Object Implements IEnumerator.Current
           Get
               Return Me.vb4ArabCollection.InnerList(location)
           End Get
       End Property

       ' MoveNext tells us what to do when user wants to move forward in the collection.
       Public Function MoveNext() As Boolean Implements IEnumerator.MoveNext
           If Me.location < Me.vb4ArabCollection.InnerList.Count - 1 Then
               Me.location += 1
               Return True
           Else
               Return False
           End If
       End Function

       ' Reset sets the initial location/position of the collection
       Public Sub Reset() Implements IEnumerator.Reset
           location = -1
       End Sub

   End Class

#End Region

End Class ' VB4ArabStringCollection
الرد }}}
تم الشكر بواسطة: الطالب , Sajad


الردود في هذا الموضوع
Collection & DataBase Part 1 - بواسطة silverlight - 23-07-15, 08:09 PM
RE: Collection & DataBase - بواسطة silverlight - 25-07-15, 07:55 AM

المواضيع المحتمل أن تكون متشابهة .
الموضوع : الكاتب الردود : المشاهدات : آخر رد
  Generic Delegates & ًWindows Forms Control - Part 2 silverlight 0 2,734 19-01-16, 02:01 PM
آخر رد: silverlight
  Generic Delegates & ًWindows Forms Control - Part 1 silverlight 1 2,920 16-01-16, 06:35 PM
آخر رد: 10468
  Collection & DataBase Part 2 silverlight 0 2,301 02-12-15, 08:42 PM
آخر رد: silverlight
  [مقال] Notify Collection Changed silverlight 3 2,656 02-11-15, 06:07 PM
آخر رد: الشاكي لله
  save rtf file in database محمد عمر مصطفى 0 2,656 21-12-13, 02:50 AM
آخر رد: محمد عمر مصطفى

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم