Strings
A free lesson from Swipe Coding · C#, level 2 · updated October 2026
By the Swipe team, founded by Colin · how we make lessons
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}");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
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
What does "Java".Substring(1, 2) return?
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
In C#, the == operator compares the actual text content of two strings, not merely whether they are the exact same object.
Strings
10 questions · pass with 60% — just like in the app.
string is a primitive type in C#, just like int or bool.
What does the + operator do when used with two strings?
The ____ property returns how many characters are in a string.
What does "Java"[0] return?
String indexes, like those used with [] and Substring(), start counting at 0.
"Java".Substring(1, 2) returns ____.
Which is the correct way to compare the text content of two strings in C#?
Once created, the contents of a string object can be changed directly.
Concatenating a string with a number using + automatically ____ the number to text.
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 →