Introduction: Dynamic Type In C#

In this post, we will learn about Dynamic Type In C# with an example.

Description:

In my previous posts I have explained various topics likeĀ  Named Arguments In C#, Basics Of Pointers In C# Get site visitor count in asp.net, Convert generic list to datatable in Asp.Net C#.Net, Abstract Class in C# with Example, Routing in Asp.Net MVC with Example,Use of Global.asax in Asp.net



Now in this post, I will explain about how to get Dynamic Type In C# with appropriate example.
‘Dynamic’ can be use to declare the variable of the dynamic type.Dynamic data type variable can store any type of value and data.Type of value contained is checked at runtime by compiler.’Dynamic’ keyword is much similar to ‘var’ keyword or you can think it as a replacement for var keyword.It is not necessary to initialize dynamic variable while declaring.

Now create Console Application in Visual Studio and write below lines of code in it.

using System;
using System.Collections;

namespace ConsoleDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("DotNetK.com");

            dynamic _Test;
            _Test = 123;
            Console.WriteLine(_Test);

            _Test = 0.234;
            Console.WriteLine(_Test);

            _Test = true;
            Console.WriteLine(_Test);

            _Test = "Live24u.com";
            Console.WriteLine(_Test);

            _Test = null;
            Console.ReadLine();
        }
    }  
}
Dynamic Type In C#

Dynamic Type In C#

Read :

Summary

I hope you got an idea about Dynamic Type In C#.
I would like to have feedback from my blog readers.
Your valuable feedback, question, or comments about this article are always welcome.

Leave a Reply

Your email address will not be published. Required fields are marked *

Name *
Email *
Website