Introduction
Strings hold text in programs. They cannot be changed once created, which helps avoid mistakes.
Strings hold text in programs. They cannot be changed once created, which helps avoid mistakes.
string name = "Hello";Strings are written inside double quotes.
Once a string is created, you cannot change its characters directly.
string greeting = "Hi"; string newGreeting = greeting + " there!";
string original = "cat";
string upper = original.ToUpper();This program shows that adding text creates a new string. The original string stays "Hello".
using System; class Program { static void Main() { string text = "Hello"; string changedText = text + " World"; Console.WriteLine(text); Console.WriteLine(changedText); } }
Strings are immutable, so operations create new strings instead of changing old ones.
This helps keep your data safe and your program predictable.
Strings hold text and are written in double quotes.
Strings cannot be changed after creation (immutable).
Any change to a string creates a new string, leaving the original unchanged.
string s = "hello"; s = s.ToUpper(); Console.WriteLine(s);
string s = "test"; s[0] = 'T'; Console.WriteLine(s);
string original = "cat";
string changed = original.Replace('c', 'b');
Console.WriteLine(original);
Console.WriteLine(changed);Pass the test and this pattern moves unknown