Tutorial by Examples: check

Extension methods are static methods which behave like instance methods. However, unlike what happens when calling an instance method on a null reference, when an extension method is called with a null reference, it does not throw a NullReferenceException. This can be quite useful in some scenarios....
The checked and unchecked keywords define how operations handle mathematical overflow. "Overflow" in the context of the checked and unchecked keywords is when an integer arithmetic operation results in a value which is greater in magnitude than the target data type can represent. When ove...
An iterator method is not executed until the return value is enumerated. It's therefore advantageous to assert preconditions outside of the iterator. public static IEnumerable<int> Count(int start, int count) { // The exception will throw when the method is called, not when the result i...
int? i = null; if (i != null) { Console.WriteLine("i is not null"); } else { Console.WriteLine("i is null"); } Which is the same as: if (i.HasValue) { Console.WriteLine("i is not null"); } else { Console.WriteLine("i is null&quot...
Java's Reflection API allows the programmer to perform various checks and operations on class fields, methods and annotations during runtime. However, in order for an annotation to be at all visible at runtime, the RetentionPolicy must be changed to RUNTIME, as demonstrated in the example below: @i...
var re = /[a-z]+/; if (re.test("foo")) { console.log("Match exists."); } The test method performs a search to see if a regular expression matches a string. The regular expression [a-z]+ will search for one or more lowercase letters. Since the pattern matches the string,...
Use array_key_exists() or isset() or !empty(): $map = [ 'foo' => 1, 'bar' => null, 'foobar' => '', ]; array_key_exists('foo', $map); // true isset($map['foo']); // true !empty($map['foo']); // true array_key_exists('bar', $map); // true isset($map['bar']); // false...
Overview Checkboxes and radio buttons are written with the HTML tag <input>, and their behavior is defined in the HTML specification. The simplest checkbox or radio button is an <input> element with a type attribute of checkbox or radio, respectively: <input type="checkbox&quo...
filter (python 3.x) and ifilter (python 2.x) return a generator so they can be very handy when creating a short-circuit test like or or and: Python 2.x2.0.1 # not recommended in real use but keeps the example short: from itertools import ifilter as filter Python 2.x2.6.1 from future_built...
a = 1 - Math.abs(1 - a % 2); // This will throw an error if my arithmetic above is wrong. assert a >= 0 && a <= 1 : "Calculated value of " + a + " is outside of expected bounds"; return a;
var favoriteColors: Set = ["Red", "Blue", "Green"] //favoriteColors = {"Blue", "Green", "Red"} You can use the contains(_:) method to check whether a set contains a value. It will return true if the set contains that value. if favorite...
Employ the EAFP coding style and try to open it. import errno try: with open(path) as f: # File exists except IOError as e: # Raise the exception if it is not ENOENT (No such file or directory) if e.errno != errno.ENOENT: raise # No such file or directory ...
To create a new branch, while staying on the current branch, use: git branch <name> Generally, the branch name must not contain spaces and is subject to other specifications listed here. To switch to an existing branch : git checkout <name> To create a new branch and switch to it...
Use the isset() function upon the superglobal $_COOKIE variable to check if a cookie is set. Example: // PHP <7.0 if (isset($_COOKIE['user'])) { // true, cookie is set echo 'User is ' . $_COOKIE['user']; else { // false, cookie is not set echo 'User is not logged in'; } ...
#include <stdio.h> #define is_const_int(x) _Generic((&x), \ const int *: "a const int", \ int *: "a non-const int", \ default: "of other type") int main(void) { const int i = 1; int j = 1; double...
3.0 Check if a string consists in exactly 8 digits: $ date=20150624 $ [[ $date =~ ^[0-9]{8}$ ]] && echo "yes" || echo "no" yes $ date=hello $ [[ $date =~ ^[0-9]{8}$ ]] && echo "yes" || echo "no" no
To begin making modifications to the project's data, you have to obtain a local copy of the versioned project. Use the command line svn client or your favorite SVN client (TortoiseSVN, for example). Your local copy of the project is called a working copy in Subversion and you get it by issuing the c...
The git check-ignore command reports on files ignored by Git. You can pass filenames on the command line, and git check-ignore will list the filenames that are ignored. For example: $ cat .gitignore *.o $ git check-ignore example.o Readme.md example.o Here, only *.o files are defined in .git...
There are three ways of creating a new branch feature which tracks the remote branch origin/feature: git checkout --track -b feature origin/feature, git checkout -t origin/feature, git checkout feature - assuming that there is no local feature branch and there is only one remote with the featur...
In this example we will write a basic program that checks the number of inputs and outputs passed to a MEX-function. As a starting point, we need to create a C++ file implementing the "MEX gateway". This is the function executed when the file is called from MATLAB. testinputs.cpp // Mat...

Page 1 of 12