n0s3c

MathUtility.cs

Nov 28th, 2019
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.19 KB | None | 0 0
  1. using Microsoft.VisualBasic;
  2.  
  3. namespace MathUtility
  4. {
  5.     // Module for identifying palindromic numbers.
  6.     public static class Palindrome
  7.     {
  8.         // Function for reversing string entries.
  9.         public static string Reverse(string value)
  10.         {
  11.             // Returns the reversed string
  12.             return Strings.StrReverse(value);
  13.         }
  14.         // Function for converting a numeric value to String.
  15.         public static string IntToString(long value)
  16.         {
  17.             // Returns a string of the numeric value.
  18.             return System.Convert.ToString(value);
  19.         }
  20.         // Function for checking if the number is palindromic.
  21.         public static bool IsPalindrome(long value)
  22.         {
  23.             // Selects the valid case.
  24.             switch (true)
  25.             {
  26.                 case object _ when value == Reverse(IntToString(value)):
  27.                     {
  28.                         // Returns true.
  29.                         return true;
  30.                     }
  31.  
  32.                 default:
  33.                     {
  34.                         // Returns false.
  35.                         return false;
  36.                     }
  37.             }
  38.         }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment