Swipe
SwipeSwipe
Swipe Apps

Paths

Motivation

Information

Strings · Lesson 25 of 27

Strings

A free lesson from Swipe Coding · C#, level 2 · updated October 2026

By the Swipe team, founded by Colin · how we make lessons

🤖
Strings look simple, but under the hood they work differently from int. 🧵

string is one of the most-used types in C#, but it works differently from the primitives you just learned: string is a reference type, not a primitive. A string variable doesn't store the text directly the way an int stores a number — it stores a reference to a string object living elsewhere in memory. In everyday code, though, you can create and use strings almost as easily as primitives.

string name = "Ada";
int points = 95;
Console.WriteLine("Hello, " + name + "!");
Console.WriteLine($"Score: {points}");
The + operator concatenates (joins) strings together, while $"..." lets you interpolate values directly into the text.
🤖
No parentheses needed for this one — it is a property, not a method. 📏

string comes with many useful members. Length is a property (not a method — no parentheses!) that tells you how many characters are in the string. You can also grab a single character at a given position, counting from 0, using square brackets right after the variable name.

string word = "Java";
Console.WriteLine(word.Length);   // 4
Console.WriteLine(word[0]);       // J
word.Length has no parentheses, since it is a property. word[0] is the character at index 0.
Fill in the blank

To find out how many characters are in a string, you read its ____ property.

The Substring(start, length) method returns a new string containing a chunk of the original: it begins at the given start position and includes exactly length characters after that.

string word = "Java";
Console.WriteLine(word.Substring(1, 2)); // av
Substring(1, 2) starts at index 1 (the second character) and takes 2 characters: "a" and "v".
Quick check

What does "Java".Substring(1, 2) return?

🤖
Once created, a string's text is locked in for good. 🔒

Strings are immutable: once a string object is created, its contents can never change. Methods like Substring() don't modify the original string — they return a brand-new string with the result. This also means you can safely use == to compare two strings in C#: it checks their actual text content, not just whether they are the same object in memory. The .Equals() method does the same comparison and is often used interchangeably with ==.

string a = "cat";
string b = "cat";
Console.WriteLine(a == b);        // True
Console.WriteLine(a.Equals(b));   // True
Because C#'s == is defined to compare content for strings, both lines print True.
True or false

In C#, the == operator compares the actual text content of two strings, not merely whether they are the exact same object.

Chapter quiz

Strings

10 questions · pass with 60% — just like in the app.

True or false

string is a primitive type in C#, just like int or bool.

Quick check

What does the + operator do when used with two strings?

Fill in the blank

The ____ property returns how many characters are in a string.

Quick check

What does "Java"[0] return?

True or false

String indexes, like those used with [] and Substring(), start counting at 0.

Fill in the blank

"Java".Substring(1, 2) returns ____.

Quick check

Which is the correct way to compare the text content of two strings in C#?

True or false

Once created, the contents of a string object can be changed directly.

Fill in the blank

Concatenating a string with a number using + automatically ____ the number to text.

Quick check

What is generally the cleanest way to combine fixed text with a variable value in C#?

Keep your streak going in Swipe Coding

Swipe through every level of C# on your iPhone — with XP, stars, streaks, a personal advisor and the full track beyond these free levels.

Get the Swipe apps →