Interviews - C# Corner

Lalit Raghav
What is dynamic keyword ?
By Lalit Raghav in C# onOct 06 2015
  • Manoj Kumar
    Jan, 2017 3

    Dynamic Keyword is the run time keyword

    • 0
  • manisha verma
    Nov, 2016 14

    dynamic is the run time bounded so it will decide the type of value on run time. its dynamic typed variable

    • 0
  • Balaji Palani
    Jun, 2016 2

    Dynamic is a new type available in .NET to bypass compiler check during variable initialization and does it on run time. It is more flexible but dangerous and needs to be used more carefully. One cool feature of dynamic is to interact with other language code and execute them, e.g., in example PythonIron is used to interact with Python code and execute it. Also, dynamic can be used with ExpandoObject class available in .NET where you can declare properties and use them on run time. In ASP.NET MVC ViewBag is used to communicate data between Controller and Views which is a good example of dynamic. The simple example to run the Python code through dynamic is as follows: (Get IronPython from NuGet)Hide Copy Codepublic static void Main(){var pythonRuntime = Python.CreateRuntime();dynamic pythonFile = pythonRuntime.UseFile("Test.py");pythonFile.SayHellotoPython();Console.ReadLine();}Where Python.py is:Hide Copy Code import sys; def SayHellotoPython();print "Hello I am Python"

    • 0
  • vipin kv
    Mar, 2016 10

    No need to initialize dynamic variables at time of decalration. var types needs to initialize at of time of declaration becuase its statically typed variable. But dynamic is dynamically typed, so we can declare it and can initialize later,also the assigned value can change any time.Explanation of dynamic ------------------------------------------ Introduced in C# 4.0 No need to initialize at the time of declaration. Errors are caught at runtime eg: e.g., dynamic str; str=”I am a string”; //Works fine and compilesstr=2; //Works fine and compiles

    • 0
  • Anil Kumar Murmu
    Jan, 2016 15

    dynamic type is inferred at run-time and not the compile time.dynamic type variables need not be initialized when declared.

    • 0

Most Popular Companies

Most Popular Job Functions

MOST LIKED QUESTIONS