# Convert code Java to c#

**URL:** <https://forum.codewithmosh.com/t/convert-code-java-to-c/742>\
**Category:** Design Patterns\
**Created:** [November 17, 2020, 6:21pm UTC](https://forum.codewithmosh.com/t/convert-code-java-to-c/742 "2020-11-17T18:21:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ahmed](https://avatars.discourse-cdn.com/v4/letter/a/8c91f0/32.png) [@ahmed](https://forum.codewithmosh.com/u/ahmed)\
**Post date:** [November 17, 2020, 6:21pm UTC](https://forum.codewithmosh.com/t/convert-code-java-to-c/742/1 "2020-11-17T18:21:28Z")

</div>

Hello, How i can use this code on C#:

public SignUpDialogBox() {  
usernameTextBox.addEventHandler(this::controlChanged);  
passwordTextBox.addEventHandler(this::controlChanged);  
agreeToTermsCheckBox.addEventHandler(this::controlChanged);  
}

```
private void controlChanged() {
    signUpButton.setEnabled(isFormValid());
}

```

Thanks

---

<div class="post-metadata">

**Author:** ![apis3445](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.codewithmosh.com/apis3445/32/497_2.png) [@apis3445](https://forum.codewithmosh.com/u/apis3445)\
**Post date:** [January 20, 2021, 2:49am UTC](https://forum.codewithmosh.com/t/convert-code-java-to-c/742/2 "2021-01-20T02:49:37Z")

</div>

I changed to inline class but it is more code. Maybe with c# event handler and delegates it is easier

```
public class ArticlesDialogBox
{
        public class ArticleObserver : IObserver
        {
            ArticlesDialogBox articlesDialogBox;
            public ArticleObserver(ArticlesDialogBox articlesDialogBox)
            {
                this.articlesDialogBox = articlesDialogBox;
            }
            public void update() => articlesDialogBox.articleSelected();
        }

        public class TitleObserver : IObserver
        {
            ArticlesDialogBox articlesDialogBox;
            public TitleObserver(ArticlesDialogBox articlesDialogBox)
            {
                this.articlesDialogBox = articlesDialogBox;
            }
            public void update() => articlesDialogBox.titleChanged();
        }

        public ArticlesDialogBox()
        {
            articlesListBox.attach(new ArticleObserver(this));
            titleTextBox.attach(new TitleObserver(this));

        }
```
