Tutorial by Examples: er

using System; using System.Dynamic; dynamic info = new ExpandoObject(); info.Id = 123; info.Another = 456; Console.WriteLine(info.Another); // 456 Console.WriteLine(info.DoesntExist); // Throws RuntimeBinderException
You can use a colon and the standard numeric format syntax to control how numbers are formatted. var decimalValue = 120.5; var asCurrency = $"It costs {decimalValue:C}"; // String value is "It costs $120.50" (depending on your local currency settings) var withThreeDecimal...
Generic methods allow the use of anonymous types through type inference. void Log<T>(T obj) { // ... } Log(new { Value = 10 }); This means LINQ expressions can be used with anonymous types: var products = new[] { new { Amount = 10, Id = 0 }, new { Amount = 20, Id = 1 }, ...
Using generic constructors would require the anonymous types to be named, which is not possible. Alternatively, generic methods may be used to allow type inference to occur. var anon = new { Foo = 1, Bar = 2 }; var anon2 = new { Foo = 5, Bar = 10 }; List<T> CreateList<T>(params T[] it...
arc4random_uniform(someNumber: UInt32) -> UInt32 This gives you random integers in the range 0 to someNumber - 1. The maximum value for UInt32 is 4,294,967,295 (that is, 2^32 - 1). Examples: Coin flip let flip = arc4random_uniform(2) // 0 or 1 Dice roll let roll = arc4random_...
What is Serialization Serialization is the process of converting an object's state (including its references) to a sequence of bytes, as well as the process of rebuilding those bytes into a live object at some future time. Serialization is used when you want to persist the object. It is also used b...
The typeof operator works on type parameters. class NameGetter<T> { public string GetTypeName() { return typeof(T).Name; } }
When json_encode or json_decode fails to parse the string provided, it will return false. PHP itself will not raise any errors or warnings when this happens, the onus is on the user to use the json_last_error() and json_last_error_msg() functions to check if an error occurred and act accordingly in ...
Interactive input To get input from the user, use the input function (note: in Python 2.x, the function is called raw_input instead, although Python 2.x has its own version of input that is completely different): Python 2.x2.3 name = raw_input("What is your name? ") # Out: What is your...
VoiceOver navigates from top-left to bottom-right, irrespective of the view hierarchy. This is usually how content is arranged in left-to-right languages since sighted individuals tend to scan the screen in an “F-shaped pattern”. VoiceOver users will expect to navigate the same way as typical users....
VoiceOver can navigate many apps on iOS because most UIKit classes implement UIAccessibilityProtocol. Features that don’t represent onscreen elements using UIView, including apps that leverage Core Graphics or Metal to perform drawing, must describe these elements for accessibility. As of iOS 8.0, t...
It is possible to force the type parameters of a generic class to implement a protocol, for example, Equatable class MyGenericClass<Type: Equatable>{ var value: Type init(value: Type){ self.value = value } func getValue() -> Type{ return self....
Scollector has built in support for using cAdvisor to generate container.* metrics in Bosun for each Docker container on a host. To get started you will need to start a new container on each docker host: docker run --name cadvisor --restart=always -d -p 8080:8080 google/cadvisor And then from an...
docker ps --format 'table {{.ID}}\t{{.Names}}\t{{.Status}}'
docker ps --filter name=myapp_1
public class CustomFormat : IFormatProvider, ICustomFormatter { public string Format(string format, object arg, IFormatProvider formatProvider) { if (!this.Equals(formatProvider)) { return null; } if (format == "Reverse") ...
Serialization with Gson is easy and will output correct JSON. public class Employe { private String firstName; private String lastName; private int age; private BigDecimal salary; private List<String> skills; //getters and setters } (Serialization) ...
SQL injection is a kind of attack that allows a malicious user to modify the SQL query, adding unwanted commands to it. For example, the following code is vulnerable: // Do not use this vulnerable code! $sql = 'SELECT name, email, user_level FROM users WHERE userID = ' . $_GET['user']; $conn->...
The return type of a method can depend on the type of the parameter. In this example, x is the parameter, A is the type of x, which is known as the type parameter. def f[A](x: A): A = x f(1) // 1 f("two") // "two" f[Float](3) // 3.0F Scala will use type infe...
There are two Dockerfile directives to specify what command to run by default in built images. If you only specify CMD then docker will run that command using the default ENTRYPOINT, which is /bin/sh -c. You can override either or both the entrypoint and/or the command when you start up the built im...

Page 35 of 417