Virgil Bevans

Virgil Bevans

  • NA
  • 16
  • 6.6k

returning a value from a method

Jan 26 2016 9:01 PM
I am confused about my inability to return a value from a method.  Both the calling method and the returning method are in the same form class definition.  Following is a simplified example of my code.
 
public class frmMain:Form
{
     public frmMain()
     {
          InitializeComponent();
     }
 
     private void getGreetingToolStripMenuItem_Click(object sender, EventArgs e)
     {
          string greeting = getGreeting()
          // some further processing such as display greeting to console
     }
 
     private string getGreeting()
     {
          return "Hello"
     }
}
 
When  I run the form the variable "greeting" is null before and after execution of the method "getGreeting()".  Near as I understand them, the dot Net help files indicate this should work; ditto for the examples I've found here and other help sites.  What am I overlooking?  Thanks.

Answers (2)