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 10-31 extrait du chapitre Le système de types
Exemple 10-30< > Exemple 10-32
Cet exemple peut être compilé avec la ligne de commande: csc.exe /target:exe Exemple_10_31.cs Erreurs: 0 Avertissements: 0 Remarque:
Exemple_10_31.cs
class Program{
static void Display(System.Text.StringBuilder s) {
System.Console.WriteLine("La chaîne : \"{0}\"",s);
System.Console.WriteLine(" Length : {0}", s.Length);
System.Console.WriteLine(" Capacity : {0}", s.Capacity);
}
public static void Main(){
System.Text.StringBuilder s = new
System.Text.StringBuilder("hello");
Display(s);
//La chaîne : "hello"
// Length : 5
// Capacity : 16
s.Insert( 4 , "--salut--" );
Display(s);
//La chaîne : "hell--salut--o"
// Length : 14
// Capacity : 16
s.Capacity = 18;
Display(s);
//La chaîne : "hell--salut--o"
// Length : 14
// Capacity : 18
s.Replace("salut","SALUT A TOUS");
Display(s);
//La chaîne : "hell--SALUT A TOUS--o"
// Length : 21
// Capacity : 36
s.EnsureCapacity(42);
Display(s);
//La chaîne : "hell--SALUT A TOUS--o"
// Length : 21
// Capacity : 72
}
}
Copyright Patrick Smacchia 2006 2007
|