Thursday, 19 December 2019

C# Session 7: Implicit vs Dynamic Variable in C#

Implicit vs Dynamic Variable



               Implicit                                                         Dynamic
   1. It got introduced in C# 3.0.
1. It got introduced in C# 4.0. 
   2. These type of variable declared using var.
   3. These type of variable gets assigned by 
       compiler at compile time.
   4. It is mandatory to initialize value 
       while declaring an implicit variable.
   5. It supports intellisense in Visual Studio.
  
   6. Post initialization to variable not allowed.



using System;


namespace CSharp.Tutorial
{
    public class Program
    {
        public static dynamic PrintInputs(dynamic value1, dynamic value2)
        {
            return value1.ToString() + value2.ToString();
        }
        static void Main(string[] args)
        {
            dynamic name;
            var value= "Tutorial"// Imilicit variable must be assigned at the time of creation
            name = "SKMDotNet";     // Dynamic variable allows post initialization.
            Console.WriteLine($"{name} and its type is: {name.GetType().ToString()}");
            Console.WriteLine(PrintInputs(1, 2));
            Console.WriteLine(PrintInputs($"{name} ", $"{value}"));
            Console.ReadLine();
        }
    }
}
2. These type of variable declared using dynamic.
3. These type of variable gets assigned by 
    compiler at run time.
4. It isn’t mandatory to initialize value 
    while declaring an dynamic variable.
5. It doesn’t supports intellisense in Visual 
    Studio.
6. Post initialization to variable are allowed.



No comments:

Post a Comment

Angular 8 Session 21 - ngFor Directive In Angular

ngFor Directive Content will be resume soon. Stay tuned!