Tutorial by Examples

If you know that a value is of a specific type, you can explicitly cast it to that type in order to use it in a context where that type is needed. object value = -1; int number = (int) value; Console.WriteLine(Math.Abs(number)); If we tried passing value directly to Math.Abs(), we would get a ...
If you aren't sure whether a value is of the type you think it is, you can safely cast it using the as operator. If the value is not of that type, the resulting value will be null. object value = "-1"; int? number = value as int?; if(number != null) { Console.WriteLine(Math.Abs(nu...
A value will automatically be cast to the appropriate type if the compiler knows that it can always be converted to that type. int number = -1; object value = number; Console.WriteLine(value); In this example, we didn't need to use the typical explicit casting syntax because the compiler knows...
If you need to know whether a value's type extends or implements a given type, but you don't want to actually cast it as that type, you can use the is operator. if(value is int) { Console.WriteLine(value + "is an int"); }
Explicit casting operators can be used to perform conversions of numeric types, even though they don't extend or implement one another. double value = -1.1; int number = (int) value; Note that in cases where the destination type has less precision than the original type, precision will be lost....
In the most basic form, it is possible to select a single variable from a table by calling the object's get_var method passing in an SQL query. global $wpdb; $user = $wpdb->get_var( "SELECT ID FROM $wpdb->users WHERE user_email='[email protected]'" ); It is very important to note that...
public class Singleton { private static class InstanceHolder { static final Singleton INSTANCE = new Singleton(); } public static Singleton getInstance() { return InstanceHolder.INSTANCE; } private Singleton() {} } This initializes the INSTANCE vari...
Prerequisites The Windows version of Elasticsearch can be obtained from this link: https://www.elastic.co/downloads/elasticsearch. The latest stable release is always at the top. As we are installing on Windows, we need the .ZIP archive. Click the link in the Downloads: section and save the file t...
add_action('init', 'process_post'); function process_post(){ if($_POST) var_dump($_POST); }
add_action('init' , function(){ echo 'i did something'; });
class sample{ public function __construct(){ add_action('init', array($this, 'samp') ); } public function samp(){ // must be public!! echo 'i did something'; } } new sample();
class sample{ public static function add_action_func(){ //note __CLASS__ will also include any namespacing add_action('init', array(__CLASS__, 'samp') ); } public static function samp(){ echo 'i did something'; } } sample::add_a...
Getting all the information of current user in wordpress using the predefined function wp_get_current_user(); <?php $current_user = wp_get_current_user(); echo "Username :".$current_user->user_login; echo "Username :".$current_user-&g...
A generator is a combination of two things - an Iterator and an Observer. Iterator An iterator is something when invoked returns an iterable. An iterable is something you can iterate upon. From ES6/ES2015 onwards, all collections (Array, Map, Set, WeakMap, WeakSet) conform to the Iterable contract...
function social_profiles( $contactmethods ) { $contactmethods['facebook_profile'] = 'Facebook Profile URL'; $contactmethods['twitter_profile'] = 'Twitter Profile URL'; $contactmethods['google_profile'] = 'Google Profile URL'; $contactmethods['linkedin_profile'] = 'Li...
function remove_contact_methods( $contactmethods ) { unset($contactmethods['facebook_profile']); unset($contactmethods['twitter_profile']); return $contactmethods; } add_filter( 'user_contactmethods', 'remove_contact_methods', 10, 1);
OpenSSL is an open source project that provides a robust, commercial-grade, and full-featured toolkit for the Transport Layer Security (TLS) and Secure Sockets Layer (SSL) protocols. It is also a general-purpose cryptography library. The OpenSSL toolkit is licensed under an Apache-style license, wh...
A Stream of items that are in turn streamable can be flattened into a single continuous Stream: Array of List of Items can be converted into a single List. List<String> list1 = Arrays.asList("one", "two"); List<String> list2 = Arrays.asList("three&quot...
To create a Grails application, use the grails create-app command. The following command creates a Grails application, named myapp in the current directory: grails create-app fancy-app Running it, is as simple as visiting the, newly created, application directory: cd fancy-app and then grai...
Package names Package names should be all lower case without underscores or other special characters. Package names begin with the reversed authority part of the web address of the company of the developer. This part can be followed a by project/program structure dependent package substructure. ...

Page 342 of 1336