Writing /home/infogasy/domains/wiki.infogasy.net/public_html/data/cache/e/ed65b4ee574e2a19c05c768bede00466.xhtml failed

27/09/2005 Mpanoratra : RTN

Fanamboarana Collection

Ity lahatsoratra iray ity dia mampiseho ny fomba fampiasana Collection amin’ny classe iray.

Toy izao voasoritra eto ambany izao ny loharanon’ny Classe Mpikambana izay ao anatin’ny vondrona IFG.Tranonkala.DAL.

Namespace IFG.Tranonkala.DAL
    Public NotInheritable Class Mpikambana
        Sub New() 
 
        End Sub           
 
        Sub New(ByVal id As Guid)
            _Id = id
        End Sub
 
  -Region " Momba ny mpikambana " 
 
        Private _Id As Guid
        Public ReadOnly Property Id() As Guid
            Get
                Return _Id
            End Get
 
        End Property 
 
        Private _Anarana As String = ""
        Public Property Anarana() As String
            Get
                Return _Anarana
            End Get
            Set(ByVal Value As String)
                _Anarana = Value
            End Set
        End Property
 
        Private _Adiresy As String = ""
        Public Property Adiresy() As String
            Get
                Return _Adiresy
            End Get
            Set(ByVal Value As String)
                _Adiresy = Value
            End Set
        End Property
  -End Region
    End Class
End Namespace
 

Raha izay ny momban’ny Classe dia asehotsika manaraka eto ny fomba famovalovalana azy anaty Collection.

Toy izao indray ny loharanon’ny Collection MpikambanaCollection

Option Strict On
Namespace IFG.Tranonkala.DAL
    Public NotInheritable Class MpikambanaCollection 'Classe tsy mampadova
       Inherits System.Collections.CollectionBase 'Fandovana CollectionBase
 
  -Region " Mpamorona "
        Public Sub New()
            MyBase.New() 'Miantso ny mpamorona reny
        End Sub
  -End Region
 
  -Region " Ireo Andraikitra "
            'Manampy mpikambana anaty Collection
        Public Overloads Function Add(ByVal ilayMpikambana As Mpikambana) As Mpikambana
            Me.InnerList.Add(ilayMpikambana)
            Return ilayMpikambana
        End Function
 
        'Maka mpikambana iray anaty Collection
        Default Public ReadOnly Property Item(ByVal Index As Integer) As Mpikambana
            Get
                Return CType(Me.InnerList.Item(Index), Mpikambana)
            End Get
 
        End Property
 
            'Manala mpikambana iray avy amin'ny laharany anaty Collection
        Public Overloads Sub Remove(ByVal Index As Integer)
            Dim ilayMpikambana As Mpikambana
            ilayMpikambana = CType(Me.InnerList.Item(Index), Mpikambana)
            Me.InnerList.Remove(ilayMpikambana)
        End Sub
 
      'Manala mpikambana iray anaty Collection
        Public Overloads Sub Remove(ByVal ilayMpikambana As Mpikambana)
            Me.InnerList.Remove(ilayMpikambana)
        End Sub
 
         'Mitady ny laharan'ny mpikambana anaty ny collection
        Public Function IndexOf(ByVal ilayMpikambana As Mpikambana) As Integer
            Return Me.InnerList.IndexOf(Mpikambana)
        End Function
 
        'Mampiditra mpikambana anaty COllection
        Public Sub Insert(ByVal Index As Integer, ByVal Value As Mpikambana)
            Me.InnerList.Insert(Index, Value)
        End Sub
 
        ' Manamarina raha ao anatin'ny Collection ilay mpikambana
        Public Function Contains(ByVal item As Mpikambana) As Boolean
            For Each itm As Mpikambana In Me.InnerList
                If itm.Id.Equals(item.Id) Then
                    Return True
                End If
            Next
            Return False
        End Function
 
  -End Region
    End Class
End Namespace
 

Alohan’ny hanazavana ny antony nanamboarana an’io Collection io dia tiako tsindriana kely ny asan’ilay teny Default eo anoloan’ny Public ReadOnly Property Item. Ilaina ny manetraka default accessor satria tsy afaka manao Serialisation ianao raha tsy misy an’io, noho izy mampiasa Icollection.Ny Serialisation moa dia ampiasaina indrindra rehefa manao WebSerive ianao.

Tsy hohazaivaiko betsaka eto intsony angambany ny asan’ireo andraikitra tsirairay avy,satria efa voazavan’ireo fitantarana kaody,fa hanolotra fotsiny ohatra fampiasana azy ho anareo izahay.

 Namespace IFG.Tranonkala.DAL.Andrana
    Public Class AndranaMpikambana
        Sub Andrana()
            Dim idMpikambana As Guid
            Dim oMpikambana As Mpikambana
            Dim ireoMpikamba As MpikambanaCollection 
 
            'Famoronana mpikambana iray
            idMpikambana = Guid.NewGuid
            oMpikambana = New Mpikambana(idMpikambana)
            oMpikambana.Anarana = "FRAZ"
            oMpikambana.Adiresy = "France"
            'Fampidirana ilay mpikamabana anaty Collection
            ireoMpikamba.Add(oMpikambana)
 
            'Famoronana mpikambana iray
            idMpikambana = Guid.NewGuid
            oMpikambana = New Mpikambana(idMpikambana)
            oMpikambana.Anarana = "Lapino"
            oMpikambana.Adiresy = "France"
            'Fampidirana ilay mpikamabana anaty Collection
            ireoMpikamba.Add(oMpikambana) 
 
            'Famoronana mpikambana iray
            idMpikambana = Guid.NewGuid
            oMpikambana = New Mpikambana(idMpikambana)
            oMpikambana.Anarana = "Hery"
            oMpikambana.Adiresy = "Italie"
            'Fampidirana ilay mpikamabana anaty Collection
            ireoMpikamba.Add(oMpikambana)
 
            'Famoronana mpikambana iray
            idMpikambana = Guid.NewGuid
            oMpikambana = New Mpikambana(idMpikambana)
            oMpikambana.Anarana = "Tambanivohitra"
            oMpikambana.Adiresy = "Madagascar"
            'Fampidirana ilay mpikamabana anaty Collection
            ireoMpikamba.Add(oMpikambana)
 
            'Famoronana mpikambana iray
            idMpikambana = Guid.NewGuid
            oMpikambana = New Mpikambana(idMpikambana)
            oMpikambana.Anarana = "RTN"
            oMpikambana.Adiresy = "France"
            'Fampidirana ilay mpikamabana anaty Collection
            ireoMpikamba.Add(oMpikambana)
 
            'Ialana tsiny Tsy hoary voatanisa eto daholo ny mpikambana rehetra
            'manjary lasa lava be ny kaody
            'fa ampidirina amin'ny lesona hafa ireo zay tsy voatonina teo
 
            'Fampisehoana ireo mpikambana
 
            For Each ilayMpikambana As Mpikambana In ireoMpikamba
                MsgBox(ilayMpikambana.Anarana & " mipetraka " & ilayMpikambana.Adiresy)
            Next
        End Sub
    End Class
End Namespace
 

Toy izao raha raketina antsary ny firafitr’ilay lamina.

Amin’ny C# V2 moa vao maika tsotra kokoa satria tsy manoratra kaody maro ianao, satria azo hatao ny mandefa ho parametre ny Type, izany hoe afaka hatao variable zany ilay As Mpikambana.

Noho izany raha manana classe hafa ianao ohatra hoe Mpiandraikitra dia Collection iray ihany no ampiasainao fa Mpiandrakitra ny Type alefanao.

Raha mampiasa .Net 2.0 ianao dia andalana iray fotsiny dia afaka manamboatra collection ianao

List<Mpikambana> lstMk= new List<Mpikambana>();

Lahatsoratra DotNET

 

fanamboaranacollection.net.txt · Novaina farany:: 2008/09/11 12:43