From 6115a71348a7a302a68bc5681f7b8faeb6c692d3 Mon Sep 17 00:00:00 2001 From: Ming Tsai Date: Tue, 19 Jan 2021 09:38:24 -0400 Subject: [PATCH] feat(strings): add is palindrome example for C# --- strings/README.md | 4 ++++ strings/csharp/palindrome.cs | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 strings/csharp/palindrome.cs 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