In C#, a string is text: an instance of System.String (the keyword string is an alias). It stores a sequence of characters—names, messages, file paths, JSON, and almost every piece of text a program prints or reads.
You create strings with double-quoted literals ("Hello"), build them with + or interpolation ($"Hi {name}"), and print them with Console.WriteLine. Strings are immutable: methods return a new string; they never change the original in place.
Five short programs that define how strings work in a C# tutorial.
Example 1 — Create and print
Assign text and display it with Console.WriteLine.
C#
using System;
class StringsIntro
{
static void Main()
{
string language = "C#";
int version = 12;
Console.WriteLine("Language: " + language);
Console.WriteLine($"Version: {version}");
Console.WriteLine("Ready to learn strings!");
}
}
A string is an instance of System.String (alias string) that stores a sequence of characters—names, messages, paths, and more. You create strings with double-quoted literals like "Hello" or interpolation $"Hi {name}".
No. Strings are immutable. Methods like ToUpper() and Concat() return a new string. For many edits in a loop, use StringBuilder.
For strings, both == and Equals() compare character content. Pass StringComparison when you need case-insensitive or ordinal rules.
Use +: string full = first + " " + last;. You can also use interpolation $"{first} {last}" or String.Concat. Prefer StringBuilder for many joins in a loop.
Practice the examples on this page, then open the String Methods index for Contains(), Equals(), Format(), and every other method guide in this C# tutorial series.