Tutorial by Examples: del

The System namespace contains Func<..., TResult> delegate types with between 0 and 15 generic parameters, returning type TResult. private void UseFunc(Func<string> func) { string output = func(); // Func with a single generic type parameter returns that type Console.WriteLine...
Named methods can be assigned to delegates with matching signatures: public static class Example { public static int AddOne(int input) { return input + 1; } } Func<int,int> addOne = Example.AddOne Example.AddOne takes an int and returns an int, its signature ...
Calling .Equals() on a delegate compares by reference equality: Action action1 = () => Console.WriteLine("Hello delegates"); Action action2 = () => Console.WriteLine("Hello delegates"); Action action1Again = action1; Console.WriteLine(action1.Equals(action1)) // True ...
Lambdas can be used to create anonymous methods to assign to a delegate: Func<int,int> addOne = x => x+1; Note that the explicit declaration of type is required when creating a variable this way: var addOne = x => x+1; // Does not work
The UITableViewDelegate is used to control how the table is displayed, and UITableViewDataSource is used to define the UITableView's data. There are two required methods and many optional ones which can be used to customize size, sections, headings, and cells in the UITableView. UITableViewDataSo...
docker rm can be used to remove a specific containers like this: docker rm <container name or id> To remove all containers you can use this expression: docker rm $(docker ps -qa) By default docker will not delete a container that is running. Any container that is running will produce a...
Create a ModelForm from an existing Model class, by subclassing ModelForm: from django import forms class OrderForm(forms.ModelForm): class Meta: model = Order fields = ['item', 'order_date', 'customer', 'status']
Many-to-One Relationship from django.db import models class Author(models.Model): name = models.CharField(max_length=50) #Book has a foreignkey (many to one) relationship with author class Book(models.Model): author = models.ForeignKey(Author, on_delete=models.CASCADE) publish_...
Many C interfaces such as SDL2 have their own deletion functions. This means that you cannot use smart pointers directly: std::unique_ptr<SDL_Surface> a; // won't work, UNSAFE! Instead, you need to define your own deleter. The examples here use the SDL_Surface structure which should be fre...
Here is a simple model that we will use to run a few test queries: class MyModel(models.Model): name = models.CharField(max_length=10) model_num = models.IntegerField() flag = models.NullBooleanField(default=False) Get a single model object where the id/pk is 4: (If there are no...
models.py : from __future__ import unicode_literals from django.db import models from django.contrib.auth.models import ( AbstractBaseUser, BaseUserManager, PermissionsMixin) from django.utils import timezone from django.utils.translation import ugettext_lazy as _ class UserManage...
You can delete data after writing it to the database. You can either delete a model instance if you have retrieved one, or specify conditions for which records to delete. To delete a model instance, retrieve it and call the delete() method: $user = User::find(1); $user->delete(); Alternat...
A model can provide a lot more information than just the data about an object. Let's see an example and break it down into what it is useful for: from django.db import models from django.urls import reverse from django.utils.encoding import python_2_unicode_compatible @python_2_unicode_compati...
Model creation Model classes must extend Illuminate\Database\Eloquent\Model. The default location for models is the /app directory. A model class can be easily generated by the Artisan command: php artisan make:model [ModelName] This will create a new PHP file in app/ by default, which is name...
Before Python 3.5+ was released, the asyncio module used generators to mimic asynchronous calls and thus had a different syntax than the current Python 3.5 release. Python 3.x3.5 Python 3.5 introduced the async and await keywords. Note the lack of parentheses around the await func() call. import ...
You should implement SFSafariViewControllerDelegate so that your class is notified when the user hits the Done button on the SafariViewController and you can dismiss it as well. First declare your class to implement the protocol. class MyClass: SFSafariViewControllerDelegate { } Implement th...
SELECT FIND_IN_SET('b','a,b,c'); Return value: 2 SELECT FIND_IN_SET('d','a,b,c'); Return value: 0
Assuming a class from django.db import models class Author(models.Model): name = models.CharField(max_length=50) def __str__(self): return self.name def get_absolute_url(self): return reverse('view_author', args=[str(self.id)]) class Book(models.Mo...
Executing code after 1.5 seconds: Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { //The code you want to run after the time is up } }, 1500); //the time you want to delay in milliseconds Executing code repeatedly every...
HTML 4.01/XHTML 1.0 Strict includes the following void elements: area - clickable, defined area in an image base - specifies a base URL from which all links base br - line break col - column in a table [deprecated] hr - horizontal rule (line) img - image input - field where users enter data...

Page 3 of 23