Skip to content

Instantly share code, notes, and snippets.

@Phuseos
Created June 22, 2016 07:27
Show Gist options
  • Select an option

  • Save Phuseos/655c697050035d56e6a04ff415243631 to your computer and use it in GitHub Desktop.

Select an option

Save Phuseos/655c697050035d56e6a04ff415243631 to your computer and use it in GitHub Desktop.
Expression bodies on method-like members (C#)
/*** Expression bodies on method-like members example ***/
/**This example shows how voids that only return methods or statements can be build using the 'lambda arrow'
The void below takes a string and returns it as a JavaScript alert window to the user **/
void CreateMessage(string Message)
{
System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('" + Message + "');", true);
}
//With the new expression body, the void will look like this:
void CreateMessage(string Message) => System.Web.UI.ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "AlertBox", "alert('" + Message + "');", true);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment