Sunday, November 12, 2017

Default values in C#

Here is the thing, C# doesn't allow you to leave a variable unitialized. What I mean is that every time you create a variable it's automatically assigned some sorta default value.

Integral types:
sbyte 0
byte 0
short 0
ushort 0
int 0
uint 0
long 0l
ulong 0ul

Floating-point types:
float 0.0f
double 0.0d
decimal 0.0m

Boolean:
bool false

Any class, struct, including these two:
object null
string null

Enumerations:
enum 0 (value of the first enumerator)

Characters:
char '\0'

No comments:

Post a Comment