// ===++=== // // OrtizOL // // ===--=== /*============================================================ // // Clase: AsignacionMemoriaStringBuilder.cs // // Propósito: Demostración del uso dinámico de memoria por // parte de StringBuilder. // ============================================================*/ using System; using System.Reflection; using System.Text; namespace Articulos.Cap06 { public class AsignacionMemoriaStringBuilder { ///<summary> /// Muestra información asociada a un objeto StringBuilder ///</summary> public static void InformacionObjetoStringBuilder(StringBuilder sb) { foreach (var propiedad in sb.GetType().GetProperties()) { if (propiedad.GetIndexParameters().Length == 0) { Console.Write("{0}: {1:N0} ", propiedad.Name, propiedad.GetValue(sb)); } } Console.WriteLine(); } public static void Main() { // Instanciación de un objeto StringBuilder StringBuilder objSB = new StringBuilder(); // Estado actual del objeto StringBuilder InformacionObjetoStringBuilder(objSB); objSB.Append("Es esta es una frase."); // Nuevo estado del objeto StringBuilder InformacionObjetoStringBuilder(objSB); for (int i = 0; i <= 10; ++i) { objSB.Append("Texto adicional."); InformacionObjetoStringBuilder(objSB); } } } }
Standard input is empty
MaxCapacity: 2,147,483,647 Capacity: 16 Length: 0 MaxCapacity: 2,147,483,647 Capacity: 21 Length: 21 MaxCapacity: 2,147,483,647 Capacity: 42 Length: 37 MaxCapacity: 2,147,483,647 Capacity: 84 Length: 53 MaxCapacity: 2,147,483,647 Capacity: 84 Length: 69 MaxCapacity: 2,147,483,647 Capacity: 168 Length: 85 MaxCapacity: 2,147,483,647 Capacity: 168 Length: 101 MaxCapacity: 2,147,483,647 Capacity: 168 Length: 117 MaxCapacity: 2,147,483,647 Capacity: 168 Length: 133 MaxCapacity: 2,147,483,647 Capacity: 168 Length: 149 MaxCapacity: 2,147,483,647 Capacity: 168 Length: 165 MaxCapacity: 2,147,483,647 Capacity: 336 Length: 181 MaxCapacity: 2,147,483,647 Capacity: 336 Length: 197