Tutorial by Examples: cas

Cast is different from the other methods of Enumerable in that it is an extension method for IEnumerable, not for IEnumerable<T>. Thus it can be used to convert instances of the former into instances of the later. This does not compile since ArrayList does not implement IEnumerable<T>: ...
The String type provides two methods for converting strings between upper case and lower case: toUpperCase to convert all characters to upper case toLowerCase to convert all characters to lower case These methods both return the converted strings as new String instances: the original String o...
123.5.to_s #=> "123.5" String(123.5) #=> "123.5" Usually, String() will just call #to_s. Methods Kernel#sprintf and String#% behave similar to C: sprintf("%s", 123.5) #=> "123.5" "%s" % 123.5 #=> "123.5" "%d&quot...
"123.50".to_i #=> 123 Integer("123.50") #=> 123 A string will take the value of any integer at its start, but will not take integers from anywhere else: "123-foo".to_i # => 123 "foo-123".to_i # => 0 However, there is a difference when ...
"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"
Getting the minimum or maximum or using sorted depends on iterations over the object. In the case of dict, the iteration is only over the keys: adict = {'a': 3, 'b': 5, 'c': 1} min(adict) # Output: 'a' max(adict) # Output: 'c' sorted(adict) # Output: ['a', 'b', 'c'] To keep the dictionary ...
Dropbox.authorizedClient!.files.download(path: path, destination: destination).response { response, error in if let (metadata, url) = response { print("*** Download file ***") print("Downloaded file name: \(metadata.name)") print("Downloaded f...
This uses the SwiftyDropbox library to upload a file from a NSData to the Dropbox account, using upload sessions for larger files, handling every error case: import UIKit import SwiftyDropbox class ViewController: UIViewController { // replace this made up data with the real data le...
This uses the SwiftyDropbox library to share a folder, handling every error case: Dropbox.authorizedClient!.sharing.shareFolder(path: "/folder_path").response { response, error in if let result = response { print("response: \(result)") } else if let callError ...
let toInvite = [Sharing.AddMember(member: Sharing.MemberSelector.Email("<EMAIL_ADDRESS_TO_INVITE>"))] Dropbox.authorizedClient!.sharing.addFolderMember(sharedFolderId: "<SHARED_FOLDER_ID>", members: toInvite).response { response, error in if (response != nil...
Cascading and specificity are used together to determine the final value of a CSS styling property. They also define the mechanisms for resolving conflicts in CSS rule sets. CSS Loading order Styles are read from the following sources, in this order: User Agent stylesheet (The styles supplied b...
The searched CASE returns results when a boolean expression is TRUE. (This differs from the simple case, which can only check for equivalency with an input.) SELECT Id, ItemId, Price, CASE WHEN Price < 10 THEN 'CHEAP' WHEN Price < 20 THEN 'AFFORDABLE' ELSE 'EXPENSIVE' E...
Use Case CASE can be used in conjunction with SUM to return a count of only those items matching a pre-defined condition. (This is similar to COUNTIF in Excel.) The trick is to return binary results indicating matches, so the "1"s returned for matching entries can be summed for a count o...
C11 Static assertions are used to check if a condition is true when the code is compiled. If it isn't, the compiler is required to issue an error message and stop the compiling process. A static assertion is one that is checked at compile time, not run time. The condition must be a constant expres...
CASE's shorthand variant evaluates an expression (usually a column) against a series of values. This variant is a bit shorter, and saves repeating the evaluated expression over and over again. The ELSE clause can still be used, though: SELECT Id, ItemId, Price, CASE Price WHEN 5 THEN 'CHEAP' ...
The strcase*-functions are not Standard C, but a POSIX extension. The strcmp function lexicographically compare two null-terminated character arrays. The functions return a negative value if the first argument appears before the second in lexicographical order, zero if they compare equal, or positi...
4.0 To uppercase $ v="hello" # Just the first character $ printf '%s\n' "${v^}" Hello # All characters $ printf '%s\n' "${v^^}" HELLO # Alternative $ v="hello world" $ declare -u string="$v" $ echo "$string" HELLO WORLD To l...
The following example shows common AngularJS constructs in one file: <!DOCTYPE html> <html ng-app="myDemoApp"> <head> <style>.started { background: gold; }</style> <script src="https://code.angularjs.org/1.5.8/angular.min.js">&lt...
This example shows the usage of the ILGenerator by generating code that makes use of already existing and new created members as well as basic Exception handling. The following code emits a DynamicAssembly that contains an equivalent to this c# code: public static class UnixTimeHelper { priva...
Performs an explicit conversion into the given type from the value resulting from evaluating the given expression. int x = 3; int y = 4; printf("%f\n", (double)x / y); /* Outputs "0.750000". */ Here the value of x is converted to a double, the division promotes the value of...

Page 1 of 14