reverse in c# code example
Example 1: c# reverse list
List<string> authors = new List<string>();
authors.Add("Your dad")
authors.Add("Your mum")
authors.Reverse();
Example 2: c# reverse string
public static string ReverseString(string s)
{
char[] arr = s.ToCharArray();
Array.Reverse(arr);
return new string(arr);
}
Example 3: c# array Reverse method
char[] array = {'a','b','c'};
Array.Reverse(array);
Example 4: c# reverse array
using System;
namespace Demo {
class MyArray {
static void Main(string[] args) {
int[] list = { 29, 15, 30, 98};
int[] temp = list;
Console.Write("Original Array: ");
foreach (int i in list) {
Console.Write(i + " ");
}
Console.WriteLine();
Array.Reverse(temp);
Console.Write("Reversed Array: ");
foreach (int i in temp) {
Console.Write(i + " ");
}
Console.ReadKey();
}
}
}