c# calling a void method
<p>I was wondering if anyone knew the answer to this problem I am having.  I am passing a delegate value to another form method called getData().  Both the delegate and the method are type void.  When I check the value in getData() all is well, it passed the correct value, but the problem I have is, I can't call the method because getData is void, so I change both the getData() method and the delegate to string and then call it, but the value changes to the a string with the name of the argument in the method and not the value from where the delegate is passed.</p>

<p>Very confused, can anyone help?</p>

<p>Results class where the delegate passes a string value from an event:</p>

<pre><code>namespace main
{
    /// &lt;summary&gt;
    /// Interaction logic for results.xaml
    /// &lt;/summary&gt;
    public partial class results : Window
    {
        public results()
        {
            InitializeComponent();
        }

        public void dataGrid1_SelectedCellsChanged(object sender, SelectedCellsChangedEventArgs e)
        {
            var dr = (DataRowView)dataGrid1.SelectedItem;
            string selection = dr["CONTRACT NUMBER"].ToString();

            //Create ref to mainwin and delegate
            MainWindow mainWin = new MainWindow();

            delPassData del = new delPassData(mainWin.getData);

            //Now close the window
            this.Close();
        }

        public delegate void delPassData(string selection);
    }
}
</code></pre>

<p>Main window with getData() method:</p>

<pre><code>namespace main
{
    /// &lt;summary&gt;
    /// Interaction logic for MainWindow.xaml
    /// &lt;/summary&gt;
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();            
        }

        private void searchBox_LostFocus(object sender, RoutedEventArgs e)
        {
            if (search != "")
            {
                try
                {
                string contractNo = getData("selection");  //Exception error, cannot explicity convert a void to an object.

                //If I change the method and the delegate from void to a string, when I call getData("selection") it returns "selection", so my questions is how do I get the value from a void method?
                }

                catch ()
                {

                }

                finally
                {

                }
            }
            else
            {

            }
        }

        public void getData(string selection);
    }
}
</code></pre>
