Tutorial by Examples: c

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);
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. ...
The .split() method splits a string into an array of substrings. By default .split() will break the string into substrings on spaces (" "), which is equivalent to calling .split(" "). The parameter passed to .split() specifies the character, or the regular expression, to use for...
Most browsers, when configured to block cookies, will also block localStorage. Attempts to use it will result in an exception. Do not forget to manage these cases. var video = document.querySelector('video') try { video.volume = localStorage.getItem('volume') } catch (error) { alert('If...
It is sometimes useful to verify that your work on Developer edition hasn't introduced a dependency on any features restricted to Enterprise edition. You can do this using the sys.dm_db_persisted_sku_features system view, like so: SELECT * FROM sys.dm_db_persisted_sku_features Against the datab...

Page 210 of 826