0Pricing
C# Academy · Lesson

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);
    }
}

All lessons in this course

  1. Local Variable Type Inference with var
  2. When to Avoid var
  3. The dynamic Type
  4. Target-Typed new Expressions
← Back to C# Academy