Tutorial by Examples: cm

6.0 Allows you to import a specific type and use the type's static members without qualifying them with the type name. This shows an example using static methods: using static System.Console; // ... string GetName() { WriteLine("Enter your name."); return ReadLine(); } ...
Given an async method like this: Task<string> GetNameAsync(CancellationToken cancellationToken) Wrap it as an IObservable<string> like this: Observable.FromAsync(cancellationToken => GetNameAsync(cancellationToken))
Methods can also have generic type parameters. public class Example { // The type parameter T is scoped to the method // and is independent of type parameters of other methods. public <T> List<T> makeList(T t1, T t2) { List<T> result = new ArrayList<T&...
With this class: class ObjectMemberVsStaticMember { static int staticCounter = 0; int memberCounter = 0; void increment() { staticCounter ++; memberCounter++; } } the following code snippet: final ObjectMemberVsStaticMember o1 = new ObjectMemberVsStati...
If you have many tasks to execute, and all these tasks are not dependent of the result of the precedent ones, you can use Multithreading for your computer to do all this tasks at the same time using more processors if your computer can. This can make your program execution faster if you have some bi...
The math module contains the math.sqrt()-function that can compute the square root of any number (that can be converted to a float) and the result will always be a float: import math math.sqrt(9) # 3.0 math.sqrt(11.11) # 3.3331666624997918 math.sqrt(Decimal('6.25')) ...
This a Basic example for using the MVVM model in a windows desktop application, using WPF and C#. The example code implements a simple "user info" dialog. The View The XAML <Grid> <Grid.ColumnDefinitions> <ColumnDefinition Width="Auto"/> ...
When type is called with three arguments it behaves as the (meta)class it is, and creates a new instance, ie. it produces a new class/type. Dummy = type('OtherDummy', (), dict(x=1)) Dummy.__class__ # <type 'type'> Dummy().__class__.__class__ # <type 'type'> It is po...
When the commits on two branches don't conflict, Git can automatically merge them: ~/Stack Overflow(branch:master) » git merge another_branch Auto-merging file_a Merge made by the 'recursive' strategy. file_a | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Both the math and cmath-module contain the Euler number: e and using it with the builtin pow()-function or **-operator works mostly like math.exp(): import math math.e ** 2 # 7.3890560989306495 math.exp(2) # 7.38905609893065 import cmath cmath.e ** 2 # 7.3890560989306495 cmath.exp(2) # (...
Supposing you have a class that stores purely integer values: class Integer(object): def __init__(self, value): self.value = int(value) # Cast to an integer def __repr__(self): return '{cls}({val})'.format(cls=self.__class__.__name__, ...
Static methods and properties are defined on the class/constructor itself, not on instance objects. These are specified in a class definition by using the static keyword. class MyClass { static myStaticMethod() { return 'Hello'; } static get myStaticProperty() { r...
The idea of bound and unbound methods was removed in Python 3. In Python 3 when you declare a method within a class, you are using a def keyword, thus creating a function object. This is a regular function, and the surrounding class works as its namespace. In the following example we declare method ...
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...
CMake generates build environments for nearly any compiler or IDE from a single project definition. The following examples will demonstrate how to add a CMake file to the cross-platform "Hello World" C++ code. CMake files are always named "CMakeLists.txt" and should already exis...
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 }, ...
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...
To run a specific migration up or down, use db:migrate:up or db:migrate:down. Up a specific migration: 5.0 rake db:migrate:up VERSION=20090408054555 5.0 rails db:migrate:up VERSION=20090408054555 Down a specific migration: 5.0 rake db:migrate:down VERSION=20090408054555 5.0 ra...
One of the first questions people have when they begin to use PowerShell for scripting is how to manipulate the output from a cmdlet to perform another action. The pipeline symbol | is used at the end of a cmdlet to take the data it exports and feed it to the next cmdlet. A simple example is using...
function Invoke-MyCmdlet { [CmdletBinding(SupportsShouldProcess = $true)] param() # ... }

Page 1 of 8