Tutorial by Examples: call

public class Animal { public string Name { get; set; } public Animal() : this("Dog") { } public Animal(string name) { Name = name; } } var dog = new Animal(); // dog.Name will be set to "Dog" by default. var cat = new Ani...
A constructor of a base class is called before a constructor of a derived class is executed. For example, if Mammal extends Animal, then the code contained in the constructor of Animal is called first when creating an instance of a Mammal. If a derived class doesn't explicitly specify which constru...
public async Task<JobResult> GetDataFromWebAsync() { var nextJob = await _database.GetNextJobAsync(); var response = await _httpClient.GetAsync(nextJob.Uri); var pageContents = await response.Content.ReadAsStringAsync(); return await _database.SaveJobResultAsync(pageContents); } ...
Calling a static method: // Single argument System.Console.WriteLine("Hello World"); // Multiple arguments string name = "User"; System.Console.WriteLine("Hello, {0}!", name); Calling a static method and storing its return value: string input = System.Con...
using System; using System.Reflection; using System.Reflection.Emit; class DemoAssemblyBuilder { public static void Main() { // An assembly consists of one or more modules, each of which // contains zero or more types. This code creates a single-module // a...
If your computation produces some return value which later is required, a simple Runnable task isn't sufficient. For such cases you can use ExecutorService.submit(Callable<T>) which returns a value after execution completes. The Service will return a Future which you can use to retrieve the r...
Static and member methods in Java can be marked as native to indicate that their implementation is to be found in a shared library file. Upon execution of a native method, the JVM looks for a corresponding function in loaded libraries (see Loading native libraries), using a simple name mangling sche...
Calling a Java method from native code is a two-step process : obtain a method pointer with the GetMethodID JNI function, using the method name and descriptor ; call one of the Call*Method functions listed here. Java code /*** com.example.jni.JNIJavaCallback.java ***/ package com.example....
Overview In this example 2 clients send information to each other through a server. One client sends the server a number which is relayed to the second client. The second client halves the number and sends it back to the first client through the server. The first client does the same. The server st...
Variables can be accessed via dynamic variable names. The name of a variable can be stored in another variable, allowing it to be accessed dynamically. Such variables are known as variable variables. To turn a variable into a variable variable, you put an extra $ put in front of your variable. $va...
Using the def statement is the most common way to define a function in python. This statement is a so called single clause compound statement with the following syntax: def function_name(parameters): statement(s) function_name is known as the identifier of the function. Since a function def...
The setTimeout() method calls a function or evaluates an expression after a specified number of milliseconds. It is also a trivial way to achieve an asynchronous operation. In this example calling the wait function resolves the promise after the time specified as first argument: function wait(ms) ...
Instead of this lambda-function that calls the method explicitly: alist = ['wolf', 'sheep', 'duck'] list(filter(lambda x: x.startswith('d'), alist)) # Keep only elements that start with 'd' # Output: ['duck'] one could use a operator-function that does the same: from operator import metho...
class adder(object): def __init__(self, first): self.first = first # a(...) def __call__(self, second): return self.first + second add2 = adder(2) add2(1) # 3 add2(2) # 4
There are several PHP functions that accept user-defined callback functions as a parameter, such as: call_user_func(), usort() and array_map(). Depending on where the user-defined callback function was defined there are different ways to pass them: Procedural style: function square($number) { ...
$ git branch -d dev Deletes the branch named dev if its changes are merged with another branch and will not be lost. If the dev branch does contain changes that have not yet been merged that would be lost, git branch -d will fail: $ git branch -d dev error: The branch 'dev' is not fully merged...
You can overload the function call operator (): Overloading must be done inside of a class/struct: //R -> Return type //Types -> any different type R operator()(Type name, Type2 name2, ...) { //Do something //return something } //Use it like this (R is return type, a and b a...
You can apply any kind of additional processing to the output by passing a callable to ob_start(). <?php function clearAllWhiteSpace($buffer) { return str_replace(array("\n", "\t", ' '), '', $buffer); } ob_start('clearAllWhiteSpace'); ?> <h1>Lorem Ipsum&l...
The extension method to be called is determined at compile-time based on the reference-type of the variable being accessed. It doesn't matter what the variable's type is at runtime, the same extension method will always be called. open class Super class Sub : Super() fun Super.myExtension()...
Given some JSON file "foo.json" like: {"foo": {"bar": {"baz": 1}}} we can call the module directly from the command line (passing the filename as an argument) to pretty-print it: $ python -m json.tool foo.json { "foo": { "bar...

Page 1 of 18