Tutorial by Examples: cs

using is syntactic sugar that allows you to guarantee that a resource is cleaned up without needing an explicit try-finally block. This means your code will be much cleaner, and you won't leak non-managed resources. Standard Dispose cleanup pattern, for objects that implement the IDisposable interf...
Setters are used to assign values to properties. string name; public string Name { set { this.name = value; } }
See RFC 2030 for details on the SNTP protocol. using System; using System.Globalization; using System.Linq; using System.Net; using System.Net.Sockets; class SntpClient { const int SntpPort = 123; static DateTime BaseDate = new DateTime(1900, 1, 1); static void Main(string[...
// Connect to a target server using your ConnectionMultiplexer instance IServer server = conn.GetServer("localhost", 6379); // Write out each key in the server foreach(var key in server.Keys()) { Console.WriteLine(key); }
Let's say you want to define an interface that allows publishing / consuming data to and from different types of channels (e.g. AMQP, JMS, etc), but you want to be able to switch out the implementation details ... Let's define a basic IO interface that can be re-used across multiple implementations...
About Protocols A Protocol specifies initialisers, properties, functions, subscripts and associated types required of a Swift object type (class, struct or enum) conforming to the protocol. In some languages similar ideas for requirement specifications of subsequent objects are known as ‘interfaces...
struct Repository { let identifier: Int let name: String var description: String? } This defines a Repository struct with three stored properties, an integer identifier, a string name, and an optional string description. The identifier and name are constants, as they've been decla...
Closures (also known as blocks or lambdas) are pieces of code which can be stored and passed around within your program. let sayHi = { print("Hello") } // The type of sayHi is "() -> ()", aka "() -> Void" sayHi() // prints "Hello" Like other fun...
Functions in Swift may return values, throw errors, or both: func reticulateSplines() // no return value and no error func reticulateSplines() -> Int // always returns a value func reticulateSplines() throws // no return value, but may throw an error func reticulat...
Copying an array will copy all of the items inside the original array. Changing the new array will not change the original array. var originalArray = ["Swift", "is", "great!"] var newArray = originalArray newArray[2] = "awesome!" //originalArray = ["...
Array is an ordered collection type in the Swift standard library. It provides O(1) random access and dynamic reallocation. Array is a generic type, so the type of values it contains are known at compile time. As Array is a value type, its mutability is defined by whether it is annotated as a var (...
For any iterable (for eg. a string, list, etc), Python allows you to slice and return a substring or sublist of its data. Format for slicing: iterable_name[start:stop:step] where, start is the first index of the slice. Defaults to 0 (the index of the first element) stop one past the last in...
CSS transforms are based on the size of the elements so if you don't know how tall or wide your element is, you can position it absolutely 50% from the top and left of a relative container and translate it by 50% left and upwards to center it vertically and horizontally. Keep in mind that with this...
Data Manipulation Language (DML for short) includes operations such as INSERT, UPDATE and DELETE: -- Create a table HelloWorld CREATE TABLE HelloWorld ( Id INT IDENTITY, Description VARCHAR(1000) ) -- DML Operation INSERT, inserting a row into the table INSERT INTO HelloWorld (D...
Classes are reference types, meaning that multiple variables can refer to the same instance. class Dog { var name = "" } let firstDog = Dog() firstDog.name = "Fido" let otherDog = firstDog // otherDog points to the same Dog instance otherDog.name = "Rover" // modifying otherDog also...
The Spinner can be reskinned according to your own style requirements using a Nine Patch. As an example, see this Nine Patch: As you can see, it has 3 extremely small areas of stretching marked. The top border has only left of the icon marked. That indicates that I want the left side (complete ...
WScript.Echo "Hello world!" This displays a message on the console if run with cscript.exe (the console host) or in a message box if run with wscript.exe (the GUI host). If you're using VBScript as the server-side scripting language for a web page (for classic ASP, for example), Respo...
Importing using base R Comma separated value files (CSVs) can be imported using read.csv, which wraps read.table, but uses sep = "," to set the delimiter to a comma. # get the file path of a CSV included in R's utils package csv_path <- system.file("misc", "exDIF.csv&q...
The term "IFrame" means Inline Frame. It can be used to include another page in your page. This will yield a small frame which shows the exact contents of the base.html. <iframe src="base.html"></iframe>
A class is a user-defined type. A class is introduced with the class, struct or union keyword. In colloquial usage, the term "class" usually refers only to non-union classes. A class is a collection of class members, which can be: member variables (also called "fields"), mem...

Page 1 of 24