Dynamic Type in C# Last Updated : 10 Apr, 2019 Comments Improve Suggest changes Like Article Like Report In C# 4.0, a new type is introduced that is known as a dynamic type. It is used to avoid the compile-time type checking. The compiler does not check the type of the dynamic type variable at compile time, instead of this, the compiler gets the type at the run time. The dynamic type variable is created using dynamic keyword. Example: dynamic value = 123; Important Points: In most of the cases, the dynamic type behaves like object types. You can get the actual type of the dynamic variable at runtime by using GetType() method. The dynamic type changes its type at the run time based on the value present on the right-hand side. As shown in the below example. Example: CSharp // C# program to illustrate how to get the // actual type of the dynamic type variable using System; class GFG { // Main Method static public void Main() { // Dynamic variables dynamic value1 = "GeeksforGeeks"; dynamic value2 = 123234; dynamic value3 = 2132.55; dynamic value4 = false; // Get the actual type of // dynamic variables // Using GetType() method Console.WriteLine("Get the actual type of value1: {0}", value1.GetType().ToString()); Console.WriteLine("Get the actual type of value2: {0}", value2.GetType().ToString()); Console.WriteLine("Get the actual type of value3: {0}", value3.GetType().ToString()); Console.WriteLine("Get the actual type of value4: {0}", value4.GetType().ToString()); } } Output: Get the actual type of value1: System.String Get the actual type of value2: System.Int32 Get the actual type of value3: System.Double Get the actual type of value4: System.Boolean When you assign a class object to the dynamic type, then the compiler does not check for the right method and property name of the dynamic type which holds the custom class object. You can also pass a dynamic type parameter in the method so that the method can accept any type of parameter at run time. As shown in the below example. Example: CSharp // C# program to illustrate how to pass // dynamic type parameters in the method using System; class GFG { // Method which contains dynamic parameters public static void addstr(dynamic s1, dynamic s2) { Console.WriteLine(s1 + s2); } // Main method static public void Main() { // Calling addstr method addstr("G", "G"); addstr("Geeks", "forGeeks"); addstr("Cat", "Dog"); addstr("Hello", 1232); addstr(12, 30); } } Output: GG GeeksforGeeks CatDog Hello1232 42 The compiler will throw an exception at runtime if the methods and the properties are not compatible. It does not support the intellisense in visual studio. The compiler does not throw an error on dynamic type at compile time if there is no type checking for dynamic type. Comment More infoAdvertise with us Next Article C# Interactive Interpreter A ankita_saini Follow Improve Article Tags : C# Similar Reads Object and Dynamic Array in C# An array is a group of like-typed variables that are referred to by a common name. And each data item is called an element of the array. The data types of the elements may be any valid data type like char, int, float, etc. and the elements are stored in a contiguous location. Object Array Object arr 2 min read C# Dictionary Dictionary in C# is a generic collection that stores key-value pairs. The working of Dictionary is quite similar to the non-generic hashtable. The advantage of a Dictionary is, that it is a generic type. A dictionary is defined under System.Collections.Generic namespace. It is dynamic in nature mean 5 min read C# Interactive Interpreter This article is designed to showcase the step by step implementation of Interactive C# Interpreter Development by virtue of .NET framework codeDOM APIâs which enables us to dynamically evaluate C# code expressions and statements for testing mini code fragments or scripts more or less like to Python 11 min read What is Anonymous Types in C#? Anonymous types in C# are the types which do not have a name or you can say the creation of new types without defining them. It is introduced in C# 3.0. It is a temporary data type which is inferred based on the data that you insert in an object initializer. Or in other words, an anonymous type prov 5 min read ref in C# The ref keyword in C# is used for passing or returning references of values to or from Methods. Basically, it means that any change made to a value that is passed by reference will reflect this change since you are modifying the value at the address and not just the value. It can be implemented in t 4 min read Introduction to C# C# (C-sharp) is a modern, object-oriented programming language developed by Microsoft as part of the .NET framework. It was first released in 2000 and it has become one of the most widely used languages for building Windows applications, web services, and more. C# combines the power of C and C++ wit 7 min read Like