Tutorial by Examples: at

The Java language provides 7 operators that perform arithmetic on integer and floating point values. There are two + operators: The binary addition operator adds one number to another one. (There is also a binary + operator that performs string concatenation. That is described in a separate e...
The == and != operators are binary operators that evaluate to true or false depending on whether the operands are equal. The == operator gives true if the operands are equal and false otherwise. The != operator gives false if the operands are equal and true otherwise. These operators can be used ...
While using the foreach loop (or "extended for loop") is simple, it's sometimes beneficial to use the iterator directly. For example, if you want to output a bunch of comma-separated values, but don't want the last item to have a comma: List<String> yourData = //... Iterator<Str...
To create your own Iterable as with any interface you just implement the abstract methods in the interface. For Iterable there is only one which is called iterator(). But its return type Iterator is itself an interface with three abstract methods. You can return an iterator associated with some coll...
This is placed in a Windows Forms event handler var nameList = new BindingList<string>(); ComboBox1.DataSource = nameList; for(long i = 0; i < 10000; i++ ) { nameList.AddRange(new [] {"Alice", "Bob", "Carol" }); } This takes a long time to execute,...
The JavaScriptSerializer.Deserialize<T>(input) method attempts to deserialize a string of valid JSON into an object of the specified type <T>, using the default mappings natively supported by JavaScriptSerializer. using System.Collections; using System.Web.Script.Serialization; // ....
internal class Sequence{ public string Name; public List<int> Numbers; } // ... string rawJSON = "{\"Name\":\"Fibonacci Sequence\",\"Numbers\":[0, 1, 1, 2, 3, 5, 8, 13]}"; Sequence sequence = JsonConvert.DeserializeObject<Seque...
There are many ways to create arrays. The most common are to use array literals, or the Array constructor: var arr = [1, 2, 3, 4]; var arr2 = new Array(1, 2, 3, 4); If the Array constructor is used with no arguments, an empty array is created. var arr3 = new Array(); results in: [] Note...
Generator expressions are very similar to list comprehensions. The main difference is that it does not create a full set of results at once; it creates a generator object which can then be iterated over. For instance, see the difference in the following code: # list comprehension [x**2 for x in r...
The multiplication operator (*) perform arithmetic multiplication on numbers (literals or variables). console.log( 3 * 5); // 15 console.log(-3 * 5); // -15 console.log( 3 * -5); // -15 console.log(-3 * -5); // 15
Exponentiation makes the second operand the power of the first operand (ab). var a = 2, b = 3, c = Math.pow(a, b); c will now be 8 6 Stage 3 ES2016 (ECMAScript 7) Proposal: let a = 2, b = 3, c = a ** b; c will now be 8 Use Math.pow to find the nth root of a number....
Variables can be incremented or decremented by 1 using the ++ and -- operators, respectively. When the ++ and -- operators follow variables, they are called post-increment and post-decrement respectively. int a = 10; a++; // a now equals 11 a--; // a now equals 10 again When the ++ and -- ope...
A single case in a switch statement can match on multiple values. let number = 3 switch number { case 1, 2: print("One or Two!") case 3: print("Three!") case 4, 5, 6: print("Four, Five or Six!") default: print("Not One, Two, Three, Four, F...
A single case in a switch statement can match a range of values. let number = 20 switch number { case 0: print("Zero") case 1..<10: print("Between One and Ten") case 10..<20: print("Between Ten and Twenty") case 20..<30: print("Be...
var x = true, y = false; AND This operator will return true if both of the expressions evaluate to true. This boolean operator will employ short-circuiting and will not evaluate y if x evaluates to false. x && y; This will return false, because y is false. OR This operator wil...
When both operands are numeric, they are compared normally: 1 < 2 // true 2 <= 2 // true 3 >= 5 // false true < false // false (implicitly converted to numbers, 1 > 0) When both operands are strings, they are compared lexicographically (according to alphabeti...
At the command line, first verify that you have Git installed: On all operating systems: git --version On UNIX-like operating systems: which git If nothing is returned, or the command is not recognized, you may have to install Git on your system by downloading and running the installer. See...
To iterate through a list you can use for: for x in ['one', 'two', 'three', 'four']: print(x) This will print out the elements of the list: one two three four The range function generates numbers which are also often used in a for loop. for x in range(1, 6): print(x) The res...
"123.50".to_f #=> 123.5 Float("123.50") #=> 123.5 However, there is a difference when the string is not a valid Float: "something".to_f #=> 0.0 Float("something") # ArgumentError: invalid value for Float(): "something"
1/2 #=> 0 Since we are dividing two integers, the result is an integer. To solve this problem, we need to cast at least one of those to Float: 1.0 / 2 #=> 0.5 1.to_f / 2 #=> 0.5 1 / Float(2) #=> 0.5 Alternatively, fdiv may be used to return the floating point result of di...

Page 7 of 442