# Max and min palindrome word in string

write a program to print max and min palindrome word in a given string:

#### Solution:

``````using System;

namespace PalindromeMax
{
class Program
{

public static void Main()
{
Console.WriteLine("Enter a string:");
var word = string.Empty;
var minPalindromeWord = string.Empty;
var maxPalindromeWord = string.Empty;
var words = new string[50];
var wordCounter = 0;
var count = 0;

str += " ";

foreach (var ch in str)
{
if (!char.IsWhiteSpace(ch))
{
word += ch;
}
else
{
words[wordCounter] = word;
wordCounter++;
word = string.Empty;
}
}

for (var i = 0; i < wordCounter; i++)
{
if (!IsPalindrome(words[i])) continue;

count++;
if (count == 1)
{
minPalindromeWord = maxPalindromeWord = words[i];
}
else
{
if (minPalindromeWord.Length > words[i].Length)
minPalindromeWord = words[i];

if (maxPalindromeWord.Length < words[i].Length)
maxPalindromeWord = words[i];
}
}

if (count == 0)
{
Console.WriteLine("No palindrome is present in string");
}
else
{
Console.WriteLine("Max palindromic: " + maxPalindromeWord);
Console.WriteLine("Min palindromic: " + minPalindromeWord);
}

}

public static bool IsPalindrome(string str)
{
var isPalindrome = true;
for (var i = 0; i < str.Length / 2; i++)
{
if (char.ToUpper(str[i]).Equals(char.ToUpper(str[str.Length - i - 1]))) continue;
isPalindrome = false;
break;
}
return isPalindrome;
}
}
}
``````