Structure dans un Collection

therafou Messages postés 46 Date d'inscription mercredi 26 février 2003 Statut Membre Dernière intervention 10 juin 2007 - 10 juin 2007 à 18:54
jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 - 11 juin 2007 à 08:56
bonjour,

je suis entrain de mettre en place une collection  avec un structure, mais le probème est que je n'arrive pas l'utiliser correctement:

voilà la déclaration:

 Public Structure info_structure
        Dim name As String
        Dim address As String
        Dim statut As String
        Dim ip As String
        Dim time As String
    End Structure

    Public Shared info As New Dictionary(Of Integer, info_structure)

ma question comment ajouter des valeurs dans ma collection:
info.Add( I, mastructure )
I étant la identifiant de mon élément dans ma collection.

Si vous saviez montrer juste un ajout et une consultation par rapport à ma collection
et si c'est faux n'hésitait pas à mon montrer une autre solution (simple si possible)
Merci d'avance

1 réponse

jrivet Messages postés 7392 Date d'inscription mercredi 23 avril 2003 Statut Membre Dernière intervention 6 avril 2012 60
11 juin 2007 à 08:56
Salut,
Je ne sais pas si cela peut t'aider mais regarde ce petit code.

Public Class Form1

   Public Structure info_structure
       Dim name As String
       Dim address As String
       Dim statut As String
       Dim ip As String
       Dim time As String
   End Structure

   Public Shared info As New Dictionary(Of Integer, info_structure)

   Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
       Dim MaStructure As info_structure
       With MaStructure
           .name = "TOTO"
           .address = "12 de la rue"
           .statut = "Bien"
           .ip = "192.168.0.1"
           .time = DateTime.Now.ToString
       End With

       Call info.Add(info.Count, MaStructure)

   End Sub<hr />
   Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Dim MaStructure As info_structure
       MaStructure = info.Item(0)
       Call MessageBox.Show(MaStructure.name)

   End Sub<hr />End Class

, ----
[code.aspx?ID=41455 By Renfield]

@+: Ju£i?n
Pensez: Réponse acceptée
0
Rejoignez-nous