FAQ - VB to C sharp net guide

Question
Define a function in c#
Answer

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;
}

}

 

Other conventions that may trap the experienced vb programmer

 

If you found this information useful, please share it!


This FAQ was last updated on 21 July 2011

Contact Information

To find out more about Ava solutions you can contact us in a number of ways:
Follow Us...