C#
Example
using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
dynamic myValue;
// myValue -This is int
myValue = 3;
// myValue -This is string
myValue = "Hello";
// myValue -This is List
myValue = new List<double>();
}
}
}
C#
Creating a new console application C# ... and write the code
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
dynamic myValue = "Hello";
myValue.book1 = 7; // property book1 we have declared nowhere
// there is no error on compilation (dynamic the object is ignored by the compiler for errors)
// RUNTIME ERROR (there is no such property)
}
}
}
C#
Example
using System;
using System.Collections.Generic;
namespace ConsoleApplication1
{
class Program
{
static void ShowValue(dynamic value)
{
Console.WriteLine(value);
}
static void Main(string[] args)
{
ShowValue(3);
ShowValue("Hello");
ShowValue(new List<double>());
}
}
}