defaultvariables.md - brainchildservices/curriculum GitHub Wiki
Slide 1
The following table shows the default values of C# Variables:
Variables | Default value |
---|---|
int | 0 (zero) |
double | 0 (zero) |
char | '\0' (U+0000) |
string | Null |
bool | False |
Slide 2
Eg:-
using System;
namespace Pluralsight
{
public class DefValues
{
public static void Main()
{
int a = default;
double c = default;
char myLetter = default;
string d = default;
bool e = default;
Console.WriteLine($"The variable: {nameof(a)} has value: {a}");
Console.WriteLine($"The variable: {nameof(b)} has value: {b}");
Console.WriteLine($"The variable: {nameof(c)} has value: {c}");
Console.WriteLine($"The variable: {nameof(d)} has value: {d}");
Console.WriteLine($"The variable: {nameof(e)} has value: {e}");
Console.ReadKey();
}
}
}
Slide 3
The output produced by the app is as follows.
The variable: a has value: 0
The variable: b has value: 0
The variable: c has value: '\0'
The variable: d has value: Null
The variable: e has value: false