Tutorial by Examples: blocks

An enum can contain a method, just like any class. To see how this works, we'll declare an enum like this: public enum Direction { NORTH, SOUTH, EAST, WEST; } Let's have a method that returns the enum in the opposite direction: public enum Direction { NORTH, SOUTH, EAST, WEST; ...
- (void)methodWithBlock:(returnType (^)(paramType1, paramType2, ...))name;
You can create multiline code snippets by indenting each line with at least four spaces or one tab: #include <stdio.h> int main() { printf("Hello World!\n"); return 0; }
Some parsers allow code to be designated by adding three backticks before and after a section of code. ``` <p><em>This</em> is an HTML example!</p> ``` Optionally, many parsers allow adding syntax highlighting by specifying the code's language immediately after the firs...
Use #region and #endregion to define a collapsible code region. #region Event Handlers public void Button_Click(object s, EventArgs e) { // ... } public void DropDown_SelectedIndexChanged(object s, EventArgs e) { // ... } #endregion These directives are only beneficial whe...
var httpClient = new HttpClient(); // Create a block the accepts a uri and returns its contents as a string var downloaderBlock = new TransformBlock<string, string>( async uri => await httpClient.GetStringAsync(uri)); // Create a block that accepts the content and prints it to t...
XML is made of basic building blocks, which are: element text attributes comments processing instructions An element has angle brackets: <element/> <element>some content</element> An attribute appears in an opening element tag: <element attribute-name="...
@interface MyObject : MySuperclass @property (copy) void (^blockProperty)(NSString *string); @end When assigning, since self retains blockProperty, block should not contain a strong reference to self. Those mutual strong references are called a "retain cycle" and will prevent the...
When adding indented code blocks inside a list you first need a blank line, then to indent the code further. Different flavours of Markdown have different rules for this. StackExchange requires code to be indented by 8 characters instead of the usual 4. (Spaces replaced with * for clarity): 1...
An identifier has block scope if its corresponding declaration appears inside a block (parameter declaration in function definition apply). The scope ends at the end of the corresponding block. No different entities with the same identifier can have the same scope, but scopes may overlap. In case o...
The only way to catch exception in initializer list: struct A : public B { A() try : B(), foo(1), bar(2) { // constructor body } catch (...) { // exceptions from the initializer list and constructor are caught here // if no exception is thrown h...
struct A { ~A() noexcept(false) try { // destructor body } catch (...) { // exceptions of destructor body are caught here // if no exception is thrown here // then the caught exception is re-thrown. } }; Note that, although this...
impl<'a> Type<'a> { fn my_function(&self) -> &'a u32 { self.x } } This specifies that Type has lifetime 'a, and that the reference returned by my_function() may no longer be valid after 'a ends because the Type no longer exists to hold self.x.
We cannot break a string into arbitrary points (because a System.Char may not be valid alone because it's a combining character or part of a surrogate) then code must take that into account (note that with length I mean the number of graphemes not the number of code-units): public static IEnumerabl...
Sometimes a element needs to be created outside of the usual object structure in the fxml. This is where Define Blocks come into play: Contents inside a <fx:define> element are not added to the object created for the parent element. Every child element of the <fx:define> needs a fx:id...
Consider the following block of code. try { using (var disposable = new MyDisposable()) { throw new Exception("Couldn't perform operation."); } } catch (Exception ex) { Console.WriteLine(ex.Message); } class MyDisposable : IDisposable { public vo...
You can send a block to your method and it can call that block multiple times. This can be done by sending a proc/lambda or such, but is easier and faster with yield: def simple(arg1,arg2) puts "First we are here: #{arg1}" yield puts "Finally we are here: #{arg2}" ...
One is able to nest one exception / try catch block inside the other. This way one can manage small blocks of code which are capable of working without disrupting your whole mechanism. try { //some code here try { //some thing which throws an exception. For Eg : divide by 0 ...
NSArray *myColors = @[@"Red", @"Green", @"Blue", @"Yellow"]; [myColors enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { NSLog(@"enumerating object %@ at index %lu", obj, idx); }]; By setting the stop parameter to YES you c...
In the early forms of Fortran the only mechanism for creating global variable store visible from subroutines and functions is to use the COMMON block mechanism. This permitted sequences of variables to be names and shared in common. In addition to named common blocks there may also be a blank (unna...

Page 1 of 3