If a static constructor throws an exception, it is never retried. The type is unusable for the lifetime of the AppDomain. Any further usages of the type will raise a TypeInitializationException wrapped around the original exception.
public class Animal
{
static Animal()
{
Consol...
Example below shows how to create a BroadcastReceiver which is able to receive BOOT_COMPLETED events. This way, you are able to start a Service or start an Activity as soon device was powered up.
Also, you can use BOOT_COMPLETED events to restore your alarms since they are destroyed when device is ...
As with docopt, with [docopt_dispatch] you craft your --help in the __doc__ variable of your entry-point module. There, you call dispatch with the doc string as argument, so it can run the parser over it.
That being done, instead of handling manually the arguments (which usually ends up in a high c...
These are the datepart values available to date & time functions:
datepartAbbreviationsyearyy, yyyyquarterqq, qmonthmm, mdayofyeardy, ydaydd, dweekwk, wwweekdaydw, whourhhminutemi, nsecondss, smillisecondmsmicrosecondmcsnanosecondns
NOTE: Use of abbreviations is generally discouraged as they c...
General syntax:
DATEDIFF (datepart, datetime_expr1, datetime_expr2)
It will return a positive number if datetime_expr is in the past relative to datetime_expr2, and a negative number otherwise.
Examples
DECLARE @now DATETIME2 = GETDATE();
DECLARE @oneYearAgo DATETIME2 = DATEADD(YEAR, -1, @now...
When defining themes, one usually uses the theme provided by the system, and then changes modifies the look to fit his own application. For example, this is how the Theme.AppCompat theme is inherited:
<style name="AppTheme" parent="Theme.AppCompat">
<item name=&quo...
Cost centers are annotations on a Haskell program which can be added automatically by the GHC compiler -- using -fprot-auto -- or by a programmer using {-# SCC "name" #-} <expression>, where "name" is any name you wish and <expression> is any valid Haskell expression:...
When you also want to expose metadata without a config file you can build on the example programmatically creating a ServiceHost:
public ConsoleHost()
{
mHost = new ServiceHost(typeof(Example), new Uri("http://localhost:8000/Example"), new Uri("net.tcp://9000/Example"));
...
Scope guards allow executing statements at certain conditions if the current block is left.
import core.stdc.stdlib;
void main() {
int* p = cast(int*)malloc(int.sizeof);
scope(exit) free(p);
}
For multiple quotechars use regex in place of sep:
df = pd.read_csv(log_file,
sep=r'\s(?=(?:[^"]*"[^"]*")*[^"]*$)(?![^\[]*\])',
engine='python',
usecols=[0, 3, 4, 5, 6, 7, 8],
names=['ip', 'time', 'request', 'statu...
The while loop runs its body as long as the condition holds. For instance, the following code computes and prints the Collatz sequence from a given number:
function collatz(n)
while n ≠ 1
println(n)
n = iseven(n) ? n ÷ 2 : 3n + 1
end
println("1... and 4, 2, 1, ...
Here is a class (Dog) creating its own dependency (Food):
class Dog {
public Dog() {
var food = new Food();
this.eat(food);
}
}
Here is the same class being injected with its dependency using constructor injection:
class Dog {
public Dog(Food food) {
...
Overview
Create a queue that we can send a message to. Oracle will notify our stored procedure that a message has been enqueued and should be worked. We'll also add some subprograms we can use in an emergency to stop messages from being deqeued, allow dequeuing again, and run a simple batch job t...
If you want to change an attribute of a control such as a textbox or label from another thread than the GUI thread that created the control, you will have to invoke it or else you might get an error message stating:
"Cross-thread operation not valid: Control 'control_name' accessed from a th...
WPF introduces a very handy concept: The ability to store data as a resource, either locally for a control, locally for the entire window or globally for the entire application. The data can be pretty much whatever you want, from actual information to a hierarchy of WPF controls. This allows you to ...
Sharing a simple string was easy, but you can do much more. In this example, I'll also store a complete array of strings, along with a gradient brush to be used for the background. This should give you a pretty good idea of just how much you can do with resources:
<Window x:Class="WPFApplic...
If you only need a given resource for a specific control, you can make it more local by adding it to this specific control, instead of the window. It works exactly the same way, the only difference being that you can now only access from inside the scope of the control where you put it:
<StackPa...
In this example, we'll be accessing three different resources from Code-behind, each stored in a different scope
App.xaml:
<Application x:Class="WpfSamples.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http:/...
If you need to send events from fragment to activity, one of the possible solutions is to define callback interface and require that the host activity implement it.
Example
Send callback to an activity, when fragment's button clicked
First of all, define callback interface:
public interface Samp...
When using C#'s inbuilt lock statement an instance of some type is needed, but its state does not matter. An instance of object is perfect for this:
public class ThreadSafe {
private static readonly object locker = new object();
public void SomeThreadSafeMethod() {
lock (locker) {
...