Strings & Text: immutability, interpolation, verbatim, StringBuilder, comparison
Understand string immutability, use interpolation, escape and verbatim strings, build text efficiently with StringBuilder, compare safely, and review char/Unicode basics.
Text overview
Goal: Use strings safely and efficiently.
- Immutability
- Interpolation & escapes
- Verbatim strings
- StringBuilder
- Comparison & culture notes
Immutability
Immutable: methods like ToUpper or Replace return new strings; originals stay the same.
using System;
public class Program
{
public static void Main(string[] args)
{
string s = "hello";
string upper = s.ToUpper(); // new string
Console.WriteLine("s = " + s); // hello
Console.WriteLine("upper = " + upper);// HELLO
string replaced = s.Replace("h", "y"); // new string
Console.WriteLine("replaced = " + replaced);
}
}
All lessons in this course
- Strings & Text: immutability, interpolation, verbatim, StringBuilder, comparison
- StringBuilder, comparison & culture notes
- char, Unicode basics, simple parsing/formatting