feat(strings): add is palindrome example for C#

pull/14/head
Ming Tsai 2021-01-19 09:38:24 -04:00
parent 5eabc052d3
commit 6115a71348
2 changed files with 23 additions and 0 deletions

View File

@ -3,3 +3,7 @@
### C or C++
1. [Palindrome Check](c-or-cpp/palindrome.c)
### C#
Please use [.Net Finddle](https://dotnetfiddle.net/)
1. [Palindrome Check](csharp/palindrome.cs)

View File

@ -0,0 +1,19 @@
using System;
using System.Linq;
public class Program
{
public static void Main()
{
bool result = false;
result = IsPalindrome("abba");
Console.WriteLine(result);
result = IsPalindrome("abbccbba");
Console.WriteLine(result);
}
private static bool IsPalindrome(string source) {
string reverse = new string(Enumerable.Range(1, source.Length).Select(i => source[source.Length - i]).ToArray());
return reverse == source;
}
}