Tutorial by Examples: action

Typically lambdas are used for defining simple functions (generally in the context of a linq expression): var incremented = myEnumerable.Select(x => x + 1); Here the return is implicit. However, it is also possible to pass actions as lambdas: myObservable.Do(x => Console.WriteLine(x)); ...
When we create a button in layout, we can use the android:onClick attribute to reference a method in code to handle clicks. Button <Button android:width="120dp" android:height="wrap_content" android:text="Click me" android:onClick="handleCl...
Buttons fire action events when they are activated (e.g. clicked, a keybinding for the button is pressed, ...). button.setOnAction(new EventHandler<ActionEvent>() { @Override public void handle(ActionEvent event) { System.out.println("Hello World!"); } }); ...
The subtraction operator (-) subtracts numbers. var a = 9; var b = 3; var c = a - b; c will now be 6 If a string or boolean is provided in place of a number value, it gets converted to a number before the difference is calculated (0 for false, 1 for true): "5" - 1; // 4 7 - ...
a, b = 1, 2 # Using the "-" operator: b - a # = 1 import operator # contains 2 argument arithmetic functions operator.sub(b, a) # = 1 Possible combinations (builtin types): int and int (gives an int) int and float (gives a float) int and comp...
6 Exceptions are to synchronous code what rejections are to promise-based asynchronous code. If an exception is thrown in a promise handler, its error will be automatically caught and used to reject the promise instead. Promise.resolve(5) .then(result => { throw new Error("I ...
// Create a block with an asynchronous action var block = new ActionBlock<string>(async hostName => { IPAddress[] ipAddresses = await Dns.GetHostAddressesAsync(hostName); Console.WriteLine(ipAddresses[0]); }); block.Post("google.com"); // Post items to the block's ...
The System namespace contains Func<..., TResult> delegate types with between 0 and 15 generic parameters, returning type TResult. private void UseFunc(Func<string> func) { string output = func(); // Func with a single generic type parameter returns that type Console.WriteLine...
While the math.sqrt function is provided for the specific case of square roots, it's often convenient to use the exponentiation operator (**) with fractional exponents to perform nth-root operations, like cube roots. The inverse of an exponentiation is exponentiation by the exponent's reciprocal. S...
Database transactions ensure that a set of data changes will only be made permanent if every statement is successful. Any query or code failure during a transaction can be caught and you then have the option to roll back the attempted changes. PDO provides simple methods for beginning, committing,...
In the material design, a Floating action button represents the primary action in an Activity. They are distinguished by a circled icon floating above the UI and have motion behaviors that include morphing, launching, and a transferring anchor point. Make sure the following dependency is added to ...
public class LogActionFilter : ActionFilterAttribute { public override void OnActionExecuting(ActionExecutingContext filterContext) { Log("OnActionExecuting", filterContext.RouteData); } public override void OnActionExecuted(ActionExecute...
To add a method to a button, first create an action method: Objective-C -(void)someButtonAction:(id)sender { // sender is the object that was tapped, in this case its the button. NSLog(@"Button is tapped"); } Swift func someButtonAction() { print("Button is tapped...
We write custom action filters for various reasons. We may have a custom action filter for logging, or for saving data to database before any action execution. We could also have one for fetching data from the database and setting it as the global values of the application. To create a custom actio...
With UIAlertController, action sheets like the deprecated UIActionSheet are created with the same API as you use for AlertViews. Simple Action Sheet with two buttons Swift let alertController = UIAlertController(title: "Demo", message: "A demo with two buttons", preferredStyle...
public static void Main() { var xml = new XmlDocument(); var root = xml.CreateElement("element"); // Creates an attribute, so the element will now be "<element attribute='value' />" root.SetAttribute("attribute", "value"); ...
By default, all types in TypeScript allow null: function getId(x: Element) { return x.id; } getId(null); // TypeScript does not complain, but this is a runtime error. TypeScript 2.0 adds support for strict null checks. If you set --strictNullChecks when running tsc (or set this flag in you...
resources :photos do member do get 'preview' end collection do get 'dashboard' end end This creates the following routes in addition to default 7 RESTful routes: get '/photos/:id/preview', to: 'photos#preview' get '/photos/dashboards', to: '...
To make a Haskell program executable you must provide a file with a main function of type IO () main :: IO () main = putStrLn "Hello world!" When Haskell is compiled it examines the IO data here and turns it into a executable. When we run this program it will print Hello world!. If y...
public function safeUp() { $this->createTable('news', [ 'id' => $this->primaryKey(), 'title' => $this->string()->notNull(), 'content' => $this->text(), ]); $this->insert('news', [ 'title' => 'test 1', 'conte...

Page 1 of 8