Tutorial by Examples: e

Once you've installed the .NET CLI tools, you can create a new project with the following command: dotnet new --lang f# This creates a command line program.
How to get the average amount of debit and credit transactions? > db.transactions.aggregate( [ { $group : { _id : '$cr_dr', // group by type of transaction (debit or credit) count : {$sum : 1}, // number of transaction for each type...
Specifies a numeric minimum and maximum range for a property using System.ComponentModel.DataAnnotations; public partial class Enrollment { public int EnrollmentID { get; set; } [Range(0, 4)] public Nullable<decimal> Grade { get; set; } } If we try to insert/upd...
Specifies how the database generates values for the property. There are three possible values: None specifies that the values are not generated by the database. Identity specifies that the column is an identity column, which is typically used for integer primary keys. Computed specifies that th...
By Code-First convention, Entity Framework creates a column for every public property that is of a supported data type and has both a getter and a setter. [NotMapped] annotation must be applied to any properties that we do NOT want a column in a database table for. An example of a property that we ...
[Table("People")] public class Person { public int PersonID { get; set; } public string PersonName { get; set; } } Tells Entity Framework to use a specific table name instead of generating one (i.e. Person or Persons) We can also specify a schema for the table using [T...
public class Person { public int PersonID { get; set; } [Column("NameOfPerson")] public string PersonName { get; set; } } Tells Entity Framework to use a specific column name instead using the name of the property. You can also specify the database data type a...
public class Person { public int PersonID { get; set; } public string PersonName { get; set; } [Index] public int Age { get; set; } } Creates a database index for a column or set of columns. [Index("IX_Person_Age")] public int Age { get; set; } This creates ...
To find active ScriptableObjects during runtime, you can use Resources.FindObjectsOfTypeAll(). T[] instances = Resources.FindObjectsOfTypeAll<T>(); Where T is the type of the ScriptableObject instance you're searching. Active means it has been loaded in memory in some form before. This me...
A shallow copy is a copy of a collection without performing a copy of its elements. >>> import copy >>> c = [[1,2]] >>> d = copy.copy(c) >>> c is d False >>> c[0] is d[0] True
If you have nested lists, it is desireable to clone the nested lists as well. This action is called deep copy. >>> import copy >>> c = [[1,2]] >>> d = copy.deepcopy(c) >>> c is d False >>> c[0] is d[0] False
You can create shallow copies of lists using slices. >>> l1 = [1,2,3] >>> l2 = l1[:] # Perform the shallow copy. >>> l2 [1,2,3] >>> l1 is l2 False
Sets also have a copymethod. You can use this method to perform a shallow copy. >>> s1 = {()} >>> s2 = s1.copy() >>> s1 is s2 False >>> s2.add(3) >>> s1 {[]} >>> s2 {3,[]}
In functional programming languages like F# null values are considered potentially harmful and poor style (non-idiomatic). Consider this C# code: string x = SomeFunction (); int l = x.Length; x.Length will throw if x is null let's add protection: string x = SomeFunction (); int l = x ...
Error handling is important but can make an elegant algorithm into a mess. Railway Oriented Programming (ROP) is used to make error handling elegant and composable. Consider the simple function f: let tryParse s = let b, v = System.Int32.TryParse s if b then Some v else None let f (g : ...
MATCH (n) WHERE n.some_attribute = "some identifier" SET n.other_attribute = "a new value"
Box Collider A primitive Collider shaped like a cuboid. Properties Is Trigger - If ticked, the Box Collider will ignore physics and become a Trigger Collider Material - A reference, if specified, to the physics material of the Box Collider Center - The Box Collider's central posit...
I create a file called database-servlet.xml somewhere on the classpath. Initially your config file will look like this: <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/...
One of the great things about Linq is that it is so easy to extend. You just need to create an extension method whose argument is IEnumerable<T>. public namespace MyNamespace { public static class LinqExtensions { public static IEnumerable<List<T>> Batch<T&...
To print a user-readable error message to stderr, call perror from <stdio.h>. int main(int argc, char *argv[]) { FILE *fout; if ((fout = fopen(argv[1], "w")) == NULL) { perror("fopen: Could not open file for writing"); return EXIT_FAILURE; } r...

Page 525 of 1191