By "class", we mean a type that was defined using the class or struct keyword (but not enum struct or enum class).
Even an empty class still occupies at least one byte of storage; it will therefore consist purely of padding. This ensures that if p points to an object of an empty class...
The static storage class specifier has three different meanings.
Gives internal linkage to a variable or function declared at namespace scope.
// internal function; can't be linked to
static double semiperimeter(double a, double b, double c) {
return (a + b + c)/2.0;
}
// exported to c...
Automapper can be installed from nuget running the following command in Package Manager Console:
Install-Package AutoMapper
Then it can be included in different files within the project it has been installed to by using directives:
using AutoMapper;
Unlike a parallel for-loop (parfor), which takes the iterations of a loop and distributes them among multiple threads, a single program, multiple data (spmd) statement takes a series of commands and distributes them to all the threads, so that each thread performs the command and stores the results....
Given a DataFrame with MultiIndex columns
# build an example DataFrame
midx = pd.MultiIndex(levels=[['zero', 'one'], ['x','y']], labels=[[1,1,0,],[1,0,1,]])
df = pd.DataFrame(np.random.randn(2,3), columns=midx)
In [2]: df
Out[2]:
one zero
y x ...
Start with a standard DataFrame
df = pd.DataFrame(np.random.randn(2,3), columns=['a','b','c'])
In [91]: df
Out[91]:
a b c
0 -0.911752 -1.405419 -0.978419
1 0.603888 -1.187064 -0.035883
Now to change to MultiIndex, create a MultiIndex object and assign it to df....
To check if a key exists in a Map, use the .has() method:
map.has(key);
Example:
const map = new Map([[1, 2], [3, 4]]);
console.log(map.has(1)); // true
console.log(map.has(2)); // false
EntityState.Added can be set in two fully equivalent ways:
By setting the state of its entry in the context:
context.Entry(entity).State = EntityState.Added;
By adding it to a DbSet of the context:
context.Entities.Add(entity);
When calling SaveChanges, the entity will be inse...
Setting the state of an object graph (a collection of related entities) to Added is different than setting a single entity as Added (see this example).
In the example, we store planets and their moons:
Class model
public class Planet
{
public Planet()
{
Moons = new HashSet<...
Using requestAnimationFrame may on some systems update at more frames per second than the 60fps. 60fps is the default rate if the rendering can keep up. Some systems will run at 120fps maybe more.
If you use the following method you should only use frame rates that are integer divisions of 60 so th...
Building project dependencies can sometimes be a tedious task. Instead of publishing a package version to NPM and installing the dependency to test the changes, use npm link. npm link creates a symlink so the latest code can be tested in a local environment. This makes testing global tools and proje...
R provides two additional looping constructs, while and repeat, which are typically used in situations where the number of iterations required is indeterminate.
The while loop
The general form of a while loop is as follows,
while (condition) {
## do something
## in loop body
}
whe...
First, let's see three different ways of extracting data from a file.
string fileText = File.ReadAllText(file);
string[] fileLines = File.ReadAllLines(file);
byte[] fileBytes = File.ReadAllBytes(file);
On the first line, we read all the data in the file as a string.
On the second line, we r...
Iterating over connected serial ports
using System.IO.Ports;
string[] ports = SerialPort.GetPortNames();
for (int i = 0; i < ports.Length; i++)
{
Console.WriteLine(ports[i]);
}
Instantiating a System.IO.SerialPort object
using System.IO.Ports;
SerialPort port = new SerialPort();
...
This example is about replacing a List element while ensuring that the replacement element is at the same position as the element that is replaced.
This can be done using these methods:
set(int index, T type)
int indexOf(T type)
Consider an ArrayList containing the elements "Program sta...
A conversion that involves calling an explicit constructor or conversion function can't be done implicitly. We can request that the conversion be done explicitly using static_cast. The meaning is the same as that of a direct initialization, except that the result is a temporary.
class C {
std:...
For a class Person like:
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
public string Clothes { get; set; }
}
var person1 = new Person { Name = "Jon", Age = 20, Clothes = "some clothes" };
var person2 = new Person { Name ...