title: c# Passing parameters on event from another class to main class
body: <p>I have a main (Form1) Class, and a second class which handles all the Serial Communication (ComPort)  </p>
  
  <p>When a new data is received through the Serial port (Event), I'd like to pass it to the Form1 and do some manipulation on this data. 
  Little Example: Creating long string from received data</p>
  
  <p>Form1.cs  </p>
  
  <pre><code>public partial class Form1 : Form  
  {  
  //Creating instance of SerialCommunication.
  ....
  ....
  string receivedString = ""; //Here I will store all data
  
  public void addNewDataMethod(string newDataFromSerial)
  { 
    receivedString = receivedString + newDataFromSerial;
    MessageBox.Show(receivedString);
  }
  </code></pre>
  
  <p>}</p>
  
  <p>SerialCommunication.cs  </p>
  
  <pre><code>public partial class SerialCommunicationPort   
      {  
        constructor()  
        {      
         .... //open serial port with the relevant parameters  
         ComPort.DataReceived += new SerialDataReceivedEventHandler(ComPortBufferRead);//Create Handler  
        }  
       public void ComPortBufferRead(object sender, SerialDataReceivedEventArgs e)  
       {  
        //create array to store buffer data  
        byte[] inputData = new byte[ComPort.BytesToRead];  
        //read the data from buffer  
        ComPort.Read(inputData, 0, ComPort.BytesToRead);  
  
      //*****  What should I write here in order to  pass "inputData" to Form1.addNewDataMethod ?
  
  
      }  
    }
  </code></pre>
  
  <p>I Tried the following:</p>
  
  <pre><code>Form1 Form;  
  Form1.addNewDataMethod(inputData.ToString());
  </code></pre>
  
  <p>The above code will generate an error: use of unassigned local variable "Form"    </p>
  
  <pre><code>Form1 Form1 = new Form1(); 
  Form1.addNewDataMethod(inputData.ToString());
  </code></pre>
  
  <p>the above will create a new instance of Form1, and will not contain the previous received data.</p>
  
  <p>Any Suggestions ?</p>