Hi,
I'm rewriting my project, so it's easier to edit in future, and want to implement interface.
I've implemented the interface, but it doesn't work in MainWindow, I'm not able to call the method.
So I've tried to use the PalindromeChecker as the default implementation PalindromeChecker = new PalindromeChecker(); , so I can call the method but it didn't work.
- interface ICheckPalindrome
- {
- bool IsPalindrome(string text);
- }
- public class PalindromeChecker : ICheckPalindrome
- {
- ///
- /// Method for checking if the word/text is a palindrome.
- ///
- public bool IsPalindrome(string text)
- {
- ......
- //Code
- }
- }
- }
- namespace TextChecker
- {
- ///
- /// Interaction logic for MainWindow.xaml
- ///
- public partial class MainWindow : Window
- {
- public MainWindow()
- {
- InitializeComponent();
- lblInput.Foreground = Brushes.ForestGreen;
- lblResult.Foreground = Brushes.ForestGreen;
- lblTitel.Foreground = Brushes.ForestGreen;
- }
- ///
- /// User input and checking the input if the word a palindrome is.
- ///
- private void InputText_TextChanged(object sender, TextChangedEventArgs e)
- {
- string text = InputText.Text;
- bool isPalindrome = PalindromeChecker.IsPalindrome(text);
- OutputText.Text = text + (isPalindrome ? " is a palindrome" : " is NOT a palindrome");
- if (InputText.Text == string.Empty)
- {
- OutputText.Clear();
- }
- }
- private void ButtonClicked(object sender, RoutedEventArgs e)
- {
- SubWindow subWindow = new SubWindow();
- subWindow.Show();
- }
- }
- }
- public class PalindromeChecker : ICheckPalindrome
- {
- ///
- /// Method for checking if the word/text is a palindrome.
- ///
- public 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--;
- }
- }
- }
Rajanikant HawaldarPosted Jul 9, 2019, 1:10 AM
Kil GorePosted Jul 9, 2019, 12:58 AM
Kil GorePosted Jul 9, 2019, 12:58 AM
Mario ScheerenPosted Jul 8, 2019, 10:16 AM