Created
April 24, 2014 03:35
-
-
Save Fhernd/11240619 to your computer and use it in GitHub Desktop.
Demostración del uso de memoria por parte un objeto StringBuilder en tiempo de ejecución.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ===++=== | |
// | |
// 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 Recetas.Ch02 | |
{ | |
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); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment