feat(strings): add is palindrome example for C#
parent
5eabc052d3
commit
6115a71348
|
@ -3,3 +3,7 @@
|
||||||
### C or C++
|
### C or C++
|
||||||
|
|
||||||
1. [Palindrome Check](c-or-cpp/palindrome.c)
|
1. [Palindrome Check](c-or-cpp/palindrome.c)
|
||||||
|
|
||||||
|
### C#
|
||||||
|
Please use [.Net Finddle](https://dotnetfiddle.net/)
|
||||||
|
1. [Palindrome Check](csharp/palindrome.cs)
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue