diff --git a/strings/README.md b/strings/README.md index 362cc48a..59917c49 100644 --- a/strings/README.md +++ b/strings/README.md @@ -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) diff --git a/strings/csharp/palindrome.cs b/strings/csharp/palindrome.cs new file mode 100644 index 00000000..7a4ced1c --- /dev/null +++ b/strings/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; + } +} \ No newline at end of file