Back to course

Working with Strings

C# Zero to Hero: Comprehensive Programming Masterclass

Mastering Strings

Strings are objects in C# that represent text.

Concatenation

Combining strings using the + operator: csharp string firstName = "John"; string lastName = "Doe"; string fullName = firstName + " " + lastName;

Interpolation

A cleaner way to format strings using $: csharp string info = $"My name is {firstName} {lastName}";

Common Methods

  • .Length: Gets the number of characters.
  • .ToUpper(): Converts to uppercase.
  • .ToLower(): Converts to lowercase.
  • .Contains(): Checks if a substring exists.