Family Day update

This commit is contained in:
Ingy döt Net 2020-02-17 23:21:07 -08:00
parent aac6731f2c
commit 9ad63ea473
2442 changed files with 39761 additions and 8255 deletions

View file

@ -3,7 +3,7 @@ using System.Collections.Generic;
static class Program
{
// TL; DR:
// In short:
public static void Foo()
{
string s;
@ -16,21 +16,21 @@ static class Program
// Check for empty string only (false if s is null):
if (s != null && s.Length == 0) { }
// Check for null or empty (most idiomatic .NET way):
// Check for null or empty (more idiomatic in .NET):
if (string.IsNullOrEmpty(s)) { }
}
public static void Main()
{
// Equality is somewhat convoluted in .NET.
// The means above are the author's recommendation for each case.
// The methods above are the author's recommendation for each case.
// s is initialized to null. It is a variable of the System.String type that is a null reference and is not
// the empty string.
string s = null;
// Alias Console.WriteLine with a shorter name to make the demonstration code less verbose.
void P(bool x) => Console.WriteLine(x);
// Alias Console.WriteLine(bool) with a shorter name to make the demonstration code less verbose.
Action<bool> P = Console.WriteLine;
// Assign the empty string literal to s.
s = "";

View file

@ -0,0 +1,15 @@
EMPTYSTR
; Demonstrate how to assign an empty string to a variable.
set x = ""
; Demonstrate how to check that a string is empty.
; Length 0 is empty; equality/pattern check are 1=T, 0=F
write !,"Assigned x to null value. Tests: "
write !,"String length: "_$length(x)_", Equals null: "_(x = "")_", Empty pattern: "_(x?."") ; length 0 is empty
; Demonstrate how to check that a string is not empty. Same as above.
set x = " " ;assign to a space - not null
write !!,"Assigned x to a single blank space. Tests: "
write !,"String length: "_$length(x)_", Equals null: "_(x = "")_", Empty pattern: "_(x?."")
quit

View file

@ -0,0 +1,23 @@
package main
import (
"fmt"
)
func test(s string) {
if len(s) == 0 {
fmt.Println("empty")
} else {
fmt.Println("not empty")
}
}
func main() {
// assign an empty string to a variable.
str1 := ""
str2 := " "
// check if a string is empty.
test(str1) // prt empty
// check that a string is not empty.
test(str2) // prt not empty
}

View file

@ -1,5 +1,5 @@
s = ''
if not s:
print('String s is empty.')
if s:
print('String s is not empty.')
if len(s) == 0:
print("String is empty")
else:
print("String not empty")

View file

@ -0,0 +1,8 @@
set "$string" to ""
if "$string.length" = 0 then "empty"
* "Not an empty string."
end
: "empty"
* "Empty string"
end

View file

@ -9,6 +9,6 @@ s = String.Empty
If s IsNot Nothing AndAlso s.Length = 0 Then
End If
' Check for null or empty (most idiomatic .NET way):
' Check for null or empty (more idiomatic in .NET):
If String.IsNullOrEmpty(s) Then
End If

View file

@ -1,19 +1,18 @@
Option Strict On
Module Program
Sub Main()
' Equality is somewhat convoluted in .NET, and VB doesn't help by adding legacy means of comparison.
' The means above are the author's recommendation for each case.
' Some methods also return true if the string is Nothing/null; this is noted in the description for those that
' The methods above are the author's recommendation for each case.
' Some also return true if the string is Nothing/null; this is noted in the description for those that
' do.
' s is initialized to Nothing. It is a variable of the System.String type that is a null reference and is not
' the empty string.
Dim s As String = Nothing
' Alias Console.WriteLine with a shorter name to make the demonstration code less verbose.
Dim P = Sub(x As Boolean) Console.WriteLine(x)
' Alias Console.WriteLine(Boolean) with a shorter name to make the demonstration code less verbose.
Dim P As Action(Of Boolean) = AddressOf Console.WriteLine
' Assign the empty string literal to s.
s = ""
@ -111,7 +110,7 @@ Module Program
Console.WriteLine()
' Each of the means described above, except testing for a non-empty string.
' Each of the methods described above, except testing for a non-empty string.
P(s IsNot "")
P(Not Object.ReferenceEquals(s, ""))
P(s <> "")