C# Strings

Beginner
8 min read
Updated: Nov 2026
5 examples
System.String

Definition and Usage

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.

This page teaches what a C# string is. The String Methods index lists every method guide (Contains(), Equals(), Format(), and more).

Immutable returns.

Write text = text.ToUpper();. Calling text.ToUpper() alone does not update text.

string vs String.

They are the same type. Prefer the keyword string for variables; either form works for static helpers like String.Format.

C# Syntax

Common ways to create and inspect strings:

C#
string literal = "Hello, C#!";        // double-quoted literal
string built   = first + " " + last;   // + concatenation
string message = $"Hi, {name}!";       // interpolation
string path    = @"C:\Users\Dev\app";  // verbatim (literal \)
int len        = text.Length;          // Length property
char ch        = text[0];              // indexer (zero-based)
bool same      = text.Equals("Hi");    // compare content

Core Ideas

Ideas every C# string tutorial builds on:

IdeaExampleRemember
Literal"Hello"Most common form
Interpolation$"Hi {name}"Embed variables in braces
Verbatim@"C:\path"Backslashes are literal
Lengthtext.LengthProperty—not a method
Indexertext[0]Zero-based char access
Immutabilitytext.ToUpper()Returns a new string

C# Examples

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!");
    }
}

How It Works

  1. string language stores a literal.
  2. + joins a string and converts the number.
  3. $"..." interpolates version directly.

Example 2 — Escapes and verbatim

Quotes, newlines, and Windows paths.

C#
using System;

class StringLiterals
{
    static void Main()
    {
        string quote = "She said, \"Hello!\"";
        string path  = @"C:\Users\Dev\project";
        string lines = "Line 1\nLine 2";

        Console.WriteLine(quote);
        Console.WriteLine(path);
        Console.WriteLine(lines);
    }
}

How It Works

  1. \" inserts a double quote.
  2. @"..." makes backslashes literal.
  3. \n starts a new line in ordinary strings.

Example 3 — Join with +, Concat, and interpolation

Build a message three common ways.

C#
using System;

class StringConcat
{
    static void Main()
    {
        string first = "Hello";
        string last  = "C#";

        string greeting = first + ", " + last + "!";
        Console.WriteLine(greeting);

        string status = String.Concat("Status: ", "Active");
        Console.WriteLine(status);

        Console.WriteLine($"{first}, {last}!");
    }
}
Concat() Tutorial

How It Works

  1. + creates a new string from parts.
  2. String.Concat is the static join helper.
  3. Interpolation is usually clearest for mixed values.

Example 4 — Length, indexer, and Equals()

Inspect characters and compare content.

C#
using System;

class StringMembers
{
    static void Main()
    {
        string word = "Hello";
        string copy = new string("Hello".ToCharArray());

        Console.WriteLine("Length: " + word.Length);
        Console.WriteLine("First: " + word[0]);
        Console.WriteLine("Equals: " + word.Equals(copy));
        Console.WriteLine("== : " + (word == copy));
    }
}
Equals() Tutorial

How It Works

  1. Length is a property counting UTF-16 code units.
  2. [0] is the first character.
  3. Equals and == are true because the text matches.

Next: C# String Methods Index

After you know what a string is, open the method index for full tutorials on every essential System.String API in this C# series.

Start withWhy
Contains()Everyday substring checks
Equals()Content equality
EndsWith()File extensions and suffixes
Format()Composite format messages

Full list: C# String Methods index (/c-sharp/string/method).

Frequently Asked Questions

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.

Browse every String method

Open the methods index for categorized guides with examples and FAQs.

String Methods Index →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.

8 people found this page helpful