/
aprogrammer
/
dotnet-docs
Обзор
Документация
Войти
/
aprogrammer
/
dotnet-docs
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
docs/fundamentals/runtime-libraries/snippets/System.Text/StringBuilder/Overview/csharp/delete1.cs
44 строки
1 KB
Genevieve Warren
Add remarks for core types (#38970)
05 янв 2024, 22:14
Не верифицирован
05 янв 2024, 22:14
71d1377
Код
Авторство
О чём код?
// <Snippet10> using System; using System.Text; public class Example5 { public static void Main() { StringBuilder sb = new StringBuilder("A StringBuilder object"); ShowSBInfo(sb); // Remove "object" from the text. string textToRemove = "object"; int pos = sb.ToString().IndexOf(textToRemove); if (pos >= 0) { sb.Remove(pos, textToRemove.Length); ShowSBInfo(sb); } // Clear the StringBuilder contents. sb.Clear(); ShowSBInfo(sb); } public static void ShowSBInfo(StringBuilder sb) { Console.WriteLine("\nValue: {0}", sb.ToString()); foreach (var prop in sb.GetType().GetProperties()) { if (prop.GetIndexParameters().Length == 0) Console.Write("{0}: {1:N0} ", prop.Name, prop.GetValue(sb)); } Console.WriteLine(); } } // The example displays the following output: // Value: A StringBuilder object // Capacity: 22 MaxCapacity: 2,147,483,647 Length: 22 // // Value: A StringBuilder // Capacity: 22 MaxCapacity: 2,147,483,647 Length: 16 // // Value: // Capacity: 22 MaxCapacity: 2,147,483,647 Length: 0 // </Snippet10>