Home
Browsez les 647 exemples
Téléchargez les 647 exemples
Téléchargez des chapitres
Achetez sur amazon.fr

Niveau: Débutant/Intermédiaire
ISBN-2-84177-339-6
50 Euros

Exemple 15-13 extrait du chapitre Collections


Exemple 15-12<     > Exemple 15-14


Cet exemple peut être compilé avec la ligne de commande:
csc.exe /target:exe Exemple_15_13.cs
Erreurs: 0 Avertissements: 0
Remarque:


Exemple_15_13.cs
using System.Collections.Generic;
class Article{
   public decimal Prix;
   public Article(decimal prix) { this.Prix = prix; }
}
public class Program {
   public static void Main() {
      Article a1 = new Article(98.5M);
      Article a2 = new Article(190M);
      ICollection<Article> collection = new List<Article>();
      collection.Add(a1);
      collection.Add(a2);
      Article[] tableau = new Article[2];
      // Copie les éléments de 'collection' dans 'tableau'.
      collection.CopyTo(tableau, 0);
      tableau[0].Prix = 80M;
      decimal = a1.Prix;
      // Ici d vaut 80. 
   }
}	
Copyright Patrick Smacchia 2006 2007