The dynamic Type
Defer type resolution to runtime with dynamic.
What is dynamic?
The dynamic type bypasses compile-time type checking. Member access and operations are resolved at runtime instead.
using System;
class Program {
static void Main() {
dynamic value = 10;
Console.WriteLine(value + 5);
}
}Reassigning Different Types
A dynamic variable can hold any type and even change type across assignments.
using System;
class Program {
static void Main() {
dynamic x = 1;
Console.WriteLine(x);
x = "now a string";
Console.WriteLine(x);
}
}