title: Returning a variable changed in void function of a class
body: <p>There's a class made to compose a word from symbols and return the word as a string. I've been struggling to make this work for hours and looks like I'm stuck. </p>
  
  <p>The class Word.cs looks like this</p>
  
  <pre><code>namespace ReturningTheValueFromVoid
  {
  
  
      class Word
      {
          string word;
  
          public void ComposeWord(char enteredSymbol)
          {
          word += enteredSymbol;
          }
  
          public string GetWord()
          {
              return word;
          }
      }
  
  
  }
  </code></pre>
  
  <p>And the class where I need to get the word (on click of the button):</p>
  
  <pre><code>namespace ReturningTheValueFromVoid
  {
      public partial class Form1 : Form
      {
  
          Word word = new Word();
          string stringWord;
  
          public Form1()
          {
              InitializeComponent();
          }
  
          private void Form1_KeyPress(object sender, KeyPressEventArgs e)
          {
              char pressedKey = e.KeyChar;
              word.ComposeWord(pressedKey);
          }
  
          private void button1_Click(object sender, EventArgs e)
          {
              stringWord = word.GetWord();
              MessageBox.Show(stringWord);
          }
      }
  }
  </code></pre>
  
  <p>So no matter how many symbols I add to my word, MessageBox returns nothing. As far as I know, the string variable "word" changes only in void function, so it can't be returned from another function. Is there a way to do this?</p>