Tutorial by Examples: c

You can use the Substring method to get any number of characters from a string at any given location. However, if you only want a single character, you can use the string indexer to get a single character at any given index like you do with an array: string s = "hello"; char c = s[1]; //...
Let us build a simple control, a rating widget, intended to be used as: <rating min="0" max="5" nullifier="true" ng-model="data.rating"></rating> No fancy CSS for now; this would render as: 0 1 2 3 4 5 x Clicking on a number selects that ra...
When you need to pass a collection into a Java method: import scala.collection.JavaConverters._ val scalaList = List(1, 2, 3) JavaLibrary.process(scalaList.asJava) If the Java code returns a Java collection, you can turn it into a Scala collection in a similar manner: import scala.collectio...
To create minification-safe angular controllers, you will change the controller function parameters. The second argument in the module.controller function should be passed an array, where the last parameter is the controller function, and every parameter before that is the name of each injected val...
defmodule Math do # We start of by passing the sum/1 function a list of numbers. def sum(numbers) do do_sum(numbers, 0) end # Recurse over the list when it contains at least one element. # We break the list up into two parts: # head: the first element of the list # ta...
.gitignore ignores files locally, but it is intended to be committed to the repository and shared with other contributors and users. You can set a global .gitignore, but then all your repositories would share those settings. If you want to ignore certain files in a repository locally and not make t...
In Elixir, a common practice is to use anonymous functions. Creating an anonymous function is simple: iex(1)> my_func = fn x -> x * 2 end #Function<6.52032458/1 in :erl_eval.expr/5> The general syntax is: fn args -> output end For readability, you may put parenthesis around t...
create table empl ( name text primary key, boss text null references name on update cascade on delete cascade default null ); insert into empl values ('Paul',null); insert into empl values ('Luke','Paul'); insert into empl values ('Kate'...
The REPLICATE function concatenates a string with itself a specified number of times. Syntax is: REPLICATE ( string-expression , integer ) SELECT REPLICATE ('Hello',4) --returns 'HelloHelloHelloHello'
Public Module Usage Public Sub LikeThis() Dim iCount As Integer Dim sCount As String iCount = 245 sCount = iCount.PadLeft(4, "0") Console.WriteLine(sCount) Console.ReadKey() End Sub End Module Public Module Padding <Extension> Pub...
A metatable defines a set of operations which alter the behaviour of a lua object. A metatable is just an ordinary table, which is used in a special way. local meta = { } -- create a table for use as metatable -- a metatable can change the behaviour of many things -- here we modify the 'tostrin...
5.2 Objects in lua are garbage collected. Sometimes, you need to free some resource, want to print a message or do something else when an object is destroyed (collected). For this, you can use the __gc metamethod, which gets called with the object as argument when the object is destroyed. You could...
There is a metamethod called __call, which defines the bevahiour of the object upon being used as a function, e.g. object(). This can be used to create function objects: -- create the metatable with a __call metamethod local meta = { __call = function(self) self.i = self.i + 1 e...
Sometimes, you don't want to trigger metamethods, but really write or read exactly the given key, without some clever functions wrapped around the access. For this, lua provides you with raw table access methods: -- first, set up a metatable that allows no read/write access local meta = { __i...
To create a background session // Swift: let mySessionID = "com.example.bgSession" let bgSessionConfig = NSURLSessionConfiguration.backgroundSessionConfigurationWithIdentifier(mySessionID) let session = NSURLSession(configuration: bgSessionConfig) // add tasks here //...
In C# 5.0 and earlier the developer could only suppress warnings by number. With the introduction of Roslyn Analyzers, C# needs a way to disable warnings issued from specific libraries. With C# 6.0 the pragma directive can suppress warnings by name. Before: #pragma warning disable 0501 C# 6.0: ...
Ionic Framework A Cross-platform mobile application development framework using Angular JS and Front End web technologies. Official website: http://ionicframework.com/ Documentation: http://ionicframework.com/docs/ Installation and Setup Installation Ionic required NPM(Node Package Manager) an...
import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingUtilities; import javax.swing.WindowConstants; /** * A very simple Swing example. */ public class SwingExample { /** * The number of times the ...
import std.stdio; void main() { int[] arr = [1, 2, 3, 4]; writeln(arr.length); // 4 writeln(arr[2]); // 3 // type inference still works auto arr2 = [1, 2, 3, 4]; writeln(typeof(arr2).stringof); // int[] }
import std.stdio; void main() { int[] arr = [1, 2, 3, 4, 5]; auto arr2 = arr[1..$ - 1]; // .. is the slice syntax, $ represents the length of the array writeln(arr2); // [2, 3, 4] arr2[0] = 42; writeln(arr[1]); // 42 }

Page 188 of 826