This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string?[] nullableStringArray = new [] | |
{ | |
"hello", | |
null, | |
"world" | |
}; | |
var valuesThatAreNotNullTrimmed = nullableStringArray | |
.Where(x => x != null) | |
.Select(x => x!.Trim()); //notice the exclamation mark here |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
string?[] nullableStringArray = new [] | |
{ | |
"hello", | |
null, | |
"world" | |
}; | |
var valuesThatAreNotNullTrimmed = nullableStringArray | |
.Where(x => x != null) | |
.Select(x => x.Trim()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool DoesUserHaveAnAdorableShippingDetailsName(User? user) { | |
var name = user | |
.ShippingDetails | |
.Name; | |
var namesSplit = name.Split(' '); | |
var firstName = namesSplit[0]; | |
var lastName = namesSplit[1]; | |
if(lastName.EndsWith("son")) | |
return false; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk"> | |
<PropertyGroup> | |
<!-- put these two properties next to the others in your property group --> | |
<LangVersion>8.0</LangVersion> | |
<Nullable>enable</Nullable> | |
</PropertyGroup> | |
</Project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Shipping details | Name | Adorable name | NullPointerException | |
---|---|---|---|---|
X | ||||
X | X | |||
X | X | |||
X | X | X |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bool DoesUserHaveAnAdorableShippingDetailsName(User user) { | |
var name = user.ShippingDetails.Name; | |
var namesSplit = name.Split(' '); | |
var firstName = namesSplit[0]; | |
var lastName = namesSplit[1]; | |
if(lastName.EndsWith("son")) | |
return false; | |
return firstName.StartsWith("Mc") && lastName.StartsWith("Fluffy"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
db.Transactions.aggregate([ | |
{ | |
"$group": { | |
"_id": null, | |
"count": { | |
"$sum": 1 | |
}, | |
"values": { | |
"$push": "$INSERT_VALUE_TO_GET_MEDIAN_OF_HERE" | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Container, Inject, Injectable } from '@fluffy-spoon/inverse'; | |
import { VueInverse, VueInjectable } from '@fluffy-spoon/inverse-vue'; | |
import Component from 'vue-class-component'; | |
import Vue from 'vue'; | |
//we first create our IOC container. | |
var container = new Container(); | |
//we provide that to the VueInverse plugin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mockedCalculator = TypeMoq.Mock.ofType(RealCalculator); | |
const calculator = mockedCalculator.object; | |
mockedCalculator.setup(x => x.isEnabled).throws(new Error()); | |
console.log(calculator.isEnabled); //throws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mockedCalculator = mock(RealCalculator); | |
const calculator = instance(mockedCalculator); | |
when(mockedCalculator.isEnabled).thenThrow(new Error()); | |
console.log(calculator.isEnabled); //throws |
NewerOlder