I made a WPF Application, called Palindrome Checker, which checks if what you input is a palindrome.
Any and all tips on how to make this code better in all capacities are wanted and appreciated.
public class Check {
/// <summary>
/// Method for checking if the word/text is a palindrome.
/// </summary>
public static bool IsPalindrome(string text) {
int min = 0;
int max = text.Length - 1;
while (true) {
if (min > max) {
return true;
}
char a = text[min];
char b = text[max];
if (a != b) {
return false;
}
min++;
max--;
}
}
}
public partial class MainWindow : Window {
public MainWindow() {
InitializeComponent();
lblInput.Foreground = Brushes.ForestGreen;
lblResult.Foreground = Brushes.ForestGreen;
lblTitel.Foreground = Brushes.ForestGreen;
}
/// <summary>
/// User input and checking the input if the word a palindrome is.
/// </summary>
private void InputText_TextChanged(object sender, TextChangedEventArgs e) {
string text = InputText.Text;
bool isPalindrome = Check.IsPalindrome(text);
OutputText.Text = text + (isPalindrome ? " is a palindrome" : " is NOT a palindrome");
if(InputText.Text == string.Empty)
OutputText.Clear();
}
}