УРОК 5 ИЗ 16
Строки, DateTime и работа с текстом
2 Теория
Строки
string s = "C# Rocks";
Console.WriteLine(s.Length); // 8
Console.WriteLine(s.ToUpper()); // C# ROCKS
Console.WriteLine(s.Substring(0, 2)); // C#
Console.WriteLine(s.Contains("Rock")); // True
Console.WriteLine(s.Replace("Rocks", "Is Fun"));
string[] parts = "a,b,c".Split(',');
Console.WriteLine(string.Join("-", parts)); // a-b-c
Console.WriteLine(string.IsNullOrWhiteSpace(" ")); // True
Console.WriteLine($"{3.14159:F2} {1234567:N0} {DateTime.Now:dd.MM.yyyy}");
Строки неизменяемы; для многократной склейки в цикле используйте StringBuilder. Сравнивайте с учётом нужной культуры: string.Equals(a, b, StringComparison.OrdinalIgnoreCase).
Дата и время
DateTime now = DateTime.Now;
DateTime birthday = new DateTime(2008, 5, 20);
TimeSpan age = now - birthday;
Console.WriteLine($"Прожито дней: {age.Days}");
Console.WriteLine(now.AddDays(30).DayOfWeek);
DateTime parsed = DateTime.Parse("2025-12-31");
bool ok = DateTime.TryParse(Console.ReadLine(), out var date);
Для хранения моментов времени в системах с пользователями из разных стран используйте UTC: DateTime.UtcNow или DateTimeOffset.
