Tutorial by Examples: comp

class Program { static void Main(string[] args) { // Create 2 thread objects. We're using delegates because we need to pass // parameters to the threads. var thread1 = new Thread(new ThreadStart(() => PerformAction(1))); var thread2 = new Thread(...
class Program { static void Main(string[] args) { // Run 2 Tasks. var task1 = Task.Run(() => PerformAction(1))); var task2 = Task.Run(() => PerformAction(2))); // Wait (i.e. block this thread) until both Tasks are complete. Task.WaitA...
// Define an expression tree, taking an integer, returning a bool. Expression<Func<int, bool>> expr = num => num < 5; // Call the Compile method on the expression tree to return a delegate that can be called. Func<int, bool> result = expr.Compile(); // Invoke the dele...
The following examples will not compile: string s = "\c"; char c = '\c'; Instead, they will produce the error Unrecognized escape sequence at compile time.
In order to compare Strings for equality, you should use the String object's equals or equalsIgnoreCase methods. For example, the following snippet will determine if the two instances of String are equal on all characters: String firstString = "Test123"; String secondString = "Test...
The AppCompat support library provides themes to build apps with the Material Design specification. A theme with a parent of Theme.AppCompat is also required for an Activity to extend AppCompatActivity. The first step is to customize your theme’s color palette to automatically colorize your app. I...
A Pattern can be compiled with flags, if the regex is used as a literal String, use inline modifiers: Pattern pattern = Pattern.compile("foo.", Pattern.CASE_INSENSITIVE | Pattern.DOTALL); pattern.matcher("FOO\n").matches(); // Is true. /* Had the regex not been compiled case...
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...
Calendar, Date, and LocalDate Java SE 8 before, after, compareTo and equals methods //Use of Calendar and Date objects final Date today = new Date(); final Calendar calendar = Calendar.getInstance(); calendar.set(1990, Calendar.NOVEMBER, 1, 0, 0, 0); Date birthdate = calendar.getTime(); ...
You should be careful when comparing floating-point values (float or double) using relational operators: ==, !=, < and so on. These operators give results according to the binary representations of the floating point values. For example: public class CompareTest { public static void main...
A list comprehension creates a new list by applying an expression to each element of an iterable. The most basic form is: [ <expression> for <element> in <iterable> ] There's also an optional 'if' condition: [ <expression> for <element> in <iterable> if <c...
A dictionary comprehension is similar to a list comprehension except that it produces a dictionary object instead of a list. A basic example: Python 2.x2.7 {x: x * x for x in (1, 2, 3, 4)} # Out: {1: 1, 2: 4, 3: 9, 4: 16} which is just another way of writing: dict((x, x * x) for x in (1, 2...
Set comprehension is similar to list and dictionary comprehension, but it produces a set, which is an unordered collection of unique elements. Python 2.x2.7 # A set containing every value in range(5): {x for x in range(5)} # Out: {0, 1, 2, 3, 4} # A set of even numbers between 1 and 10: {x f...
Given a list comprehension you can append one or more if conditions to filter values. [<expression> for <element> in <iterable> if <condition>] For each <element> in <iterable>; if <condition> evaluates to True, add <expression> (usually a function...
You can compare multiple items with multiple comparison operators with chain comparison. For example x > y > z is just a short form of: x > y and y > z This will evaluate to True only if both comparisons are True. The general form is a OP b OP c OP d ... Where OP represents ...
There is a complementary function for filter in the itertools-module: Python 2.x2.0.1 # not recommended in real use but keeps the example valid for python 2.x and python 3.x from itertools import ifilterfalse as filterfalse Python 3.x3.0.0 from itertools import filterfalse which works...
To check the equality of Date values: var date1 = new Date(); var date2 = new Date(date1.valueOf() + 10); console.log(date1.valueOf() === date2.valueOf()); Sample output: false Note that you must use valueOf() or getTime() to compare the values of Date objects because the equality operato...
Composition provides an alternative to inheritance. A struct may include another type by name in its declaration: type Request struct { Resource string } type AuthenticatedRequest struct { Request Username, Password string } In the example above, AuthenticatedRequest will con...
Warning: be sure you have at least 15 GB of free disk space. Compilation in Ubuntu >=13.04 Option A) Use Git Use git if you want to stay in sync with the latest Ubuntu kernel source. Detailed instructions can be found in the Kernel Git Guide. The git repository does not include necessary ...
Python's str type also features a number of methods that can be used to evaluate the contents of a string. These are str.isalpha, str.isdigit, str.isalnum, str.isspace. Capitalization can be tested with str.isupper, str.islower and str.istitle. str.isalpha str.isalpha takes no arguments and retu...

Page 1 of 34