Skip to content

Reverse a string

C# reverse a string

Same task in: C#

Flowchart (ISO 5807)

StartInput sr = «»i = |s| − 1, 0, −1r = r + s[i]Return rEndFigure 1 — Program.Reverse

Source code

C#
class Program {
    static string Reverse(string s) {
        string r = "";
        for (int i = s.Length - 1; i >= 0; i--) {
            r += s[i];
        }
        return r;
    }
}

The editor opens with this code — change it and the chart redraws.

Language
C#
Constructs
reverse a string
Topic
Algorithms
Formats
Word, Visio, draw.io, PDF, SVG

Related examples