How do I define a function in c#?
We the smart answer is that c# does not have functions which does not get us anywhere fast. We rise above this ans say what is the equivalnt of a vb function in c sharp? For this example we have a save function, we need to return if it was sucessful:
open a new c# windows form project
throw a button on the form:
private void button1_Click(object sender, EventArgs e)
{
//add the code the button triggers
bool yn = SaveEmailSettings();
}
//declare a "function" and ensure it returns a value on all
paths....
private bool SaveEmailSettings()
{
try
{
// saving code here
return true;
}
catch (Exception)
{
return false;
throw;
}
}
|
© 2009 Added Value Applications
|