Рядок
string
— це послідовність символів. Рядки використовуються для зберігання текстових даних.
main.cs
1234567891011121314using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "Hello, World!"; Console.WriteLine(text); // Output: Hello, World! } } }
Текстові дані, або рядки, завжди беруться у подвійні лапки ("
).
Арифметичні операції над рядками виконувати не можна, але оператор плюс (+
) дозволяє об'єднувати два рядки. Цей процес називається конкатенацією рядків.
main.cs
123456789101112131415using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string partOne = "The first sentence. "; string partTwo = "The second sentence."; string combined = partOne + partTwo; Console.WriteLine(combined); // Output: The first sentence. The second sentence. } } }
Можна використовувати символ нового рядка (\n
), щоб позначити новий рядок у рядкових даних.
Розгляньте наступний приклад:
main.cs
12345678910111213using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "The first line.\nThe second line."; Console.WriteLine(text); } } }
Коли зустрічається символ \n
, текст автоматично переходить на новий рядок. Можна використовувати декілька символів нового рядка, щоб пропустити кілька рядків:
main.cs
12345678910111213using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "The first line.\n\n\nThe second line.\nThe third line."; Console.WriteLine(text); } } }
Дякуємо за ваш відгук!
Запитати АІ
Запитати АІ
Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат
Can you show me an example of string concatenation?
How does the new line character work in practice?
Can you explain more about how to use special characters in strings?
Awesome!
Completion rate improved to 1.59
Рядок
Свайпніть щоб показати меню
string
— це послідовність символів. Рядки використовуються для зберігання текстових даних.
main.cs
1234567891011121314using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "Hello, World!"; Console.WriteLine(text); // Output: Hello, World! } } }
Текстові дані, або рядки, завжди беруться у подвійні лапки ("
).
Арифметичні операції над рядками виконувати не можна, але оператор плюс (+
) дозволяє об'єднувати два рядки. Цей процес називається конкатенацією рядків.
main.cs
123456789101112131415using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string partOne = "The first sentence. "; string partTwo = "The second sentence."; string combined = partOne + partTwo; Console.WriteLine(combined); // Output: The first sentence. The second sentence. } } }
Можна використовувати символ нового рядка (\n
), щоб позначити новий рядок у рядкових даних.
Розгляньте наступний приклад:
main.cs
12345678910111213using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "The first line.\nThe second line."; Console.WriteLine(text); } } }
Коли зустрічається символ \n
, текст автоматично переходить на новий рядок. Можна використовувати декілька символів нового рядка, щоб пропустити кілька рядків:
main.cs
12345678910111213using System; namespace ConsoleApp { internal class Program { static void Main(string[] args) { string text = "The first line.\n\n\nThe second line.\nThe third line."; Console.WriteLine(text); } } }
Дякуємо за ваш відгук!