fork download
  1. // ===++===
  2. //
  3. // OrtizOL
  4. //
  5. // ===--===
  6. /*============================================================
  7. //
  8. // Clase: AsignacionMemoriaStringBuilder.cs
  9. //
  10. // Propósito: Demostración del uso dinámico de memoria por
  11. // parte de StringBuilder.
  12. //
  13. ============================================================*/
  14.  
  15. using System;
  16. using System.Reflection;
  17. using System.Text;
  18.  
  19. namespace Articulos.Cap06
  20. {
  21. public class AsignacionMemoriaStringBuilder
  22. {
  23. ///<summary>
  24. /// Muestra información asociada a un objeto StringBuilder
  25. ///</summary>
  26. public static void InformacionObjetoStringBuilder(StringBuilder sb)
  27. {
  28. foreach (var propiedad in sb.GetType().GetProperties())
  29. {
  30. if (propiedad.GetIndexParameters().Length == 0)
  31. {
  32. Console.Write("{0}: {1:N0} ", propiedad.Name, propiedad.GetValue(sb));
  33. }
  34. }
  35. Console.WriteLine();
  36. }
  37.  
  38. public static void Main()
  39. {
  40. // Instanciación de un objeto StringBuilder
  41. StringBuilder objSB = new StringBuilder();
  42.  
  43. // Estado actual del objeto StringBuilder
  44. InformacionObjetoStringBuilder(objSB);
  45.  
  46. objSB.Append("Es esta es una frase.");
  47.  
  48. // Nuevo estado del objeto StringBuilder
  49. InformacionObjetoStringBuilder(objSB);
  50.  
  51. for (int i = 0; i <= 10; ++i)
  52. {
  53. objSB.Append("Texto adicional.");
  54. InformacionObjetoStringBuilder(objSB);
  55. }
  56. }
  57. }
  58. }
Success #stdin #stdout 0.06s 24008KB
stdin
Standard input is empty
stdout
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