Quick actions

cmd+k|ctrl+k

Navigation

Languages

Udemy: Master Coding Interview - Arrays - #68

Snippet info

Language

Csharp

Visibility

public

Author

jcurrie33

Created

2020-08-02T08:44:07Z

Updated

2020-08-02T08:46:34Z

using System;

// Create a function that reverses a string:
// 'Hi My name is Andrei' should be:
// 'ierdnA si eman yM iH'
class MainClass {
    static void Main() {
        string name = "Hi My name is Andrei";
        Console.WriteLine("name = " + name);
        Console.WriteLine("name reversed = " + reverse(name));
    }
    
    static string reverse(string s) {
        char[] c = s.ToCharArray();
        char[] cReversed = new char[c.Length];
        for (int i = 0; i < c.Length; i++) {
            cReversed[c.Length - i - 1] = c[i];
        }
        return new string(cReversed);
    }
}
INFO