Skip to content

Instantly share code, notes, and snippets.

@angelovstanton
Created September 6, 2015 09:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save angelovstanton/306098ad12c7d5c476b9 to your computer and use it in GitHub Desktop.
Save angelovstanton/306098ad12c7d5c476b9 to your computer and use it in GitHub Desktop.
dynamic dynamicVariable;
int i = 20;
dynamicVariable = (dynamic)i;
Console.WriteLine(dynamicVariable);
string stringVariable = "Example string.";
dynamicVariable = (dynamic)stringVariable;
Console.WriteLine(dynamicVariable);
DateTime dateTimeVariable = DateTime.Today;
dynamicVariable = (dynamic)dateTimeVariable;
Console.WriteLine(dynamicVariable);
// The expression returns true unless dynamicVariable has the value null.
if (dynamicVariable is dynamic)
{
Console.WriteLine("d variable is dynamic");
}
// dynamic and the as operator.
dynamicVariable = i as dynamic;
// throw RuntimeBinderException if the associated object doesn't have the specified method.
// The code is still compiling successfully.
Console.WriteLine(dynamicVariable.ToNow1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment