Strings
A string prefixed with $ is an interpolated string — expressions inside {braces} are evaluated and inserted directly, which is usually clearer than building a string with +.
Main.cs
Try it yourself →using System;
class Program {
static void Main() {
string name = "world";
string greeting = $"Hello, {name}!";
Console.WriteLine(greeting);
Console.WriteLine(greeting.Length);
}
}Output
Hello, world! 13
== actually compares content
Unlike Java, where == on strings compares object references and .equals() is needed for content comparison, C#'s == operator is overloaded for string to compare content directly — two strings built completely separately still compare equal if their characters match.
Main.cs
Try it yourself →using System;
class Program {
static void Main() {
string a = "hello";
string b = "hel" + "lo";
Console.WriteLine(a == b);
}
}Output
True
Next: classes and objects — defining a class, fields, and constructors.
Practice exercise
Given string name = "Rust", use string interpolation to print "Learning Rust today".