Namespace: System

String Class

Represents text as a sequence of zero or more 16-bit unsigned integer (UTF-16) code units. Strings in .NET are immutable, meaning their value cannot be changed after they are created.
Summary

The System.String class is fundamental to text manipulation in .NET. It provides a rich set of methods for creating, comparing, searching, and modifying strings. Because strings are immutable, any operation that appears to modify a string actually creates a new string instance.

Constructors
Properties
Methods
Operators
Examples

using System;

public class StringExample
{
    public static void Main(string[] args)
    {
        string greeting = "Hello, World!";
        Console.WriteLine(greeting); // Output: Hello, World!

        string name = "Alice";
        string message = string.Concat("Welcome, ", name, "!");
        Console.WriteLine(message); // Output: Welcome, Alice!

        string sentence = "The quick brown fox jumps over the lazy dog.";
        bool containsFox = sentence.Contains("fox");
        Console.WriteLine($"Does the sentence contain 'fox'? {containsFox}"); // Output: Does the sentence contain 'fox'? True

        int index = sentence.IndexOf("jumps");
        Console.WriteLine($"The word 'jumps' starts at index: {index}"); // Output: The word 'jumps' starts at index: 20

        string upperCase = greeting.ToUpper();
        Console.WriteLine($"Uppercase version: {upperCase}"); // Output: Uppercase version: HELLO, WORLD!

        string trimmed = "   Trim me!   ";
        Console.WriteLine($"Trimmed: '{trimmed.Trim()}'"); // Output: Trimmed: 'Trim me!'
    }
}