The string Type
In this page:
The string Type
A string is an immutable sequence of characters, written with double quotes. Strings support concatenation with +, interpolation with $"...", and a rich set of built-in methods. Because strings are immutable, every "modification" actually creates a new string.
Note: Prefer string interpolation ($"Hello {name}") over concatenation for readability.
Example: The string Type
using System;
class Program
{
static void Main(string[] args)
{
string first = "Ada";
string last = "Lovelace";
string full = first + " " + last;
string greeting = $"Hello, {full}!";
Console.WriteLine(full);
Console.WriteLine(greeting);
Console.WriteLine(full.Length);
Console.WriteLine(full.ToUpper());
}
}
Login to try C/C++/Java/PHP code in the editor
🔒
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: