Tutorial by Examples

Copying a partial array with the static Array.Copy() method, beginning at index 0 in both, source and destination: var sourceArray = new int[] { 11, 12, 3, 5, 2, 9, 28, 17 }; var destinationArray= new int[3]; Array.Copy(sourceArray, destinationArray, 3); // destinationArray will have 11,12 and...
This code is to add and remove a value from a flagged enum-instance: [Flags] public enum MyEnum { Flag1 = 1 << 0, Flag2 = 1 << 1, Flag3 = 1 << 2 } var value = MyEnum.Flag1; // set additional value value |= MyEnum.Flag2; //value is now Flag1, Flag2 value...
Sometimes we need to make a lot of POST requests to one or many different endpoints. To deal with this scenario, we can use multi_curl. First of all, we create how many requests as needed exactly in the same way of the simple example and put them in an array. We use the curl_multi_init and add eac...
Elm Reactor is the essential tool for prototyping your application. Please note, that you will not be able to compile Main.elm with Elm Reactor, if you are using Http.App.programWithFlags or Ports Running elm-reactor in a projects directory will start a web server with a project explorer, that all...
To create a XML using DOMDocument,basically, we need to create all the tags and attributes using the createElement() and createAttribute() methods and them create the XML structure with the appendChild(). The example below includes tags, attributes, a CDATA section and a different namespace for the...
Following the 'Form Request Validation' example, the same Request Class can be used for POST, PUT, PATCH so you do not have to create another class using the same/similar validations. This comes in handy if you have attributes in your table that are unique. /** * Get the validation rules that a...
Xdebug is a PHP extension which provides debugging and profiling capabilities. It uses the DBGp debugging protocol. There are some nice features in this tool: stack traces on errors maximum nesting level protection and time tracking helpful replacement of standard var_dump() function for displ...
Just like most other C-style languages, each statement is terminated with a semicolon. Also, a closing tag is used to terminate the last line of code of the PHP block. If the last line of PHP code ends with a semicolon, the closing tag is optional if there is no code following that final line of co...
Anonymous classes were introduced into PHP 7 to enable for quick one-off objects to be easily created. They can take constructor arguments, extend other classes, implement interfaces, and use traits just like normal classes can. In its most basic form, an anonymous class looks like the following: ...
C++14 Those following string user literals are declared in the namespace std::literals::string_literals, where both literals and string_literals are inline namespaces. Access to these operators can be gained with using namespace std::literals, using namespace std::string_literals, and using namespa...
Assertations mean that a condition should be checked and if it's false, it's an error. For static_assert(), this is done compile-time. template<typename T> T mul10(const T t) { static_assert( std::is_integral<T>::value, "mul10() only works for integral types" ); re...
A default constructor is a type of constructor that requires no parameters when called. It is named after the type it constructs and is a member function of it (as all constructors are). class C{ int i; public: // the default constructor definition C() : i(0){ // member initial...
A destructor is a function without arguments that is called when a user-defined object is about to be destroyed. It is named after the type it destructs with a ~ prefix. class C{ int* is; string s; public: C() : is( new int[10] ){ } ~C(){ // destructor definition ...
See below for a simple example of how to use async/await to do some time intensive stuff in a background process while maintaining the option of doing some other stuff that do not need to wait on the time intensive stuff to complete. However, if you need to work with the result of the time intensiv...
See below for a simple example of how to use a BackgroundWorker object to perform time-intensive operations in a background thread. You need to: Define a worker method that does the time-intensive work and call it from an event handler for the DoWork event of a BackgroundWorker. Start the execu...
See below for a simple example of how to use a Task to do some time intensive stuff in a background process. All you need to do is wrap your time intensive method in a Task.Run() call. public void ProcessDataAsync() { // Start the time intensive method Task<int> t = Task.Run(() =&...
See below for a simple example of how to use a Thread to do some time intensive stuff in a background process. public async void ProcessDataAsync() { // Start the time intensive method Thread t = new Thread(TimeintensiveMethod); // Control returns here before TimeintensiveMethod r...
Subscripts can be used to simplify retrieving and setting elements in an array. Given the following array NSArray *fruit = @[@"Apples", @"Bananas", @"Cherries"]; This line [fruit objectAtIndex: 1]; Can be replaced by fruit[1]; They can also be used to set an...
Subscripts can also be used with NSDictionary and NSMutableDictionary. The following code: NSMutableDictionary *myDictionary = [@{@"Foo": @"Bar"} mutableCopy]; [myDictionary setObject:@"Baz" forKey:@"Foo"]; NSLog(@"%@", [myDictionary objectForKey:...
You can add subscripting to your own classes by implementing the required methods. For indexed subscripting (like arrays): - (id)objectAtIndexedSubscript:(NSUInteger)idx - (void)setObject:(id)obj atIndexedSubscript:(NSUInteger)idx For keyed subscripting (like dictionaries): - (id)objectForKey...

Page 511 of 1336