C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
Finally: The values that were assigned are printed to the screen. The null value is printed as a blank line.
NullC# program that uses default expression
using System;
using System.Text;
class Program
{
static void Main()
{
// Acquire the default values for these types and assign to a variable.
StringBuilder variable1 = default(StringBuilder);
int variable2 = default(int);
bool variable3 = default(bool);
Program variable4 = default(Program);
// Write the values.
Console.WriteLine(variable1); // Null
Console.WriteLine(variable2); // 0
Console.WriteLine(variable3); // False
Console.WriteLine(variable4); // Null
}
}
Output
(Blank)
0
False
(Blank)
So: No reflection to the type system or metadata relational database is used at runtime.
ILAnd: Unlike with typeof expressions, caching the default expression would have no benefit.
Typeof, nameof