
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
How to define dynamic data types in C#
You can store any type of value in the dynamic data type variable. Type checking for these types of variables takes place at run-time. C# 4.0 introduced the dynamic type that avoids compile time type checking.
The following is the syntax for declaring a dynamic type −
dynamic <variable_name> = value;
Dynamic types are similar to object types except that type checking for object type variables takes place at compile time, whereas that for the dynamic type variables takes place at run time.
Let us see an example −
dynamic a = 25;
To get the type of dynamic variable −
Example
using System; namespace Demo { class Program { static void Main(string[] args) { dynamic a = 25; Console.WriteLine(a.GetType().ToString()); Console.ReadLine(); } } }
- Related Articles
- What are dynamic data types in C#?
- Why JavaScript Data Types are Dynamic?
- What is Dynamic Testing? (Types, Techniques, Example)
- Dynamic Finger Search Trees in Data Structure
- What are the types of Dynamic Branch Prediction?
- Define Respiration and its types.
- Dynamic Programming: return all matched data in JavaScript
- Difference between fundamental data types and derived data types in C++
- Data Types in C
- Data types in Java
- Dynamic highlight data point on Excel chart
- Define cash books and its types
- Define Disease. Also, explain its types.
- Difference between Fundamental data types and derived Data Types
- How to convert JavaScript objects to primitive data types manually?

Advertisements