Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default value of dynamic type?

Tags:

c#

clr

c#-4.0

What is the default value of a variable declared as dynamic e.g. private dynamic banana;?

Can I rely on the default() function when the type is determined at runtime?

The reason I need to find the default value is that I declare a dynamic member of a class that I want to set it once (but not as readonly), then use it many times.

How do I check if the dynamic variable has been set to anything other than the default value without knowing what the runtime type is likely to be?

Google came up with nothing on this :S

Thanks in advance.

like image 461
Sinker Avatar asked Apr 05 '13 06:04

Sinker


1 Answers

It is null.

dynamic blah;
Console.Write(blah); // crash
Console.Write(blah.GetType()); // NullRef

..is that what you meant?

like image 170
Simon Whitehead Avatar answered Sep 25 '22 15:09

Simon Whitehead