Dynamic Keyword in Dart

Dynamic Keyword in Dart

ยท

1 min read

  • Dart dynamic type In Dart, when a variable is declared as a dynamic type, it can store any value, such as int , String and float . The value of a dynamic variable can change over time within the program.
// dynamic type  
void main()
{
  // declaring and assigning value to variable a 
  // of type dynamic
  dynamic a = 40;
  print(a);
  // reassigning value to a
  a= "Dart";
  print(a);
  // reassigning value to a
  a= 10.4;
  print(a);
}
  • In here , We declare a variable named a of dynamic type and assign an integer value to it. than we print the value after that agian we have assign a string value to it. and print the value and in the last we have print assign float value and print it

    • Like in var we can done this type of process , because var support only one data type at that time which is the biggest different between var and dynamic keyword.
ย