Dart: Variable
Welcome to the series post.
The is the first post about Dart
From today I am starting Dart language tutorial.
I already posted a brief introduction about dart and I also try to answer why you choose the dart programming. Check this Dart Introduction
In the previous post, I write about some important concept about dart. Before starting I recommend for taking a look.
Main method:
First, see the code:
In the code, you see that the parameter of the main method is a list of string. I think this is as usual of other programming languages. But most interesting part is that you can also create the main method without this parameter.
So, That's so simple.
Now write a hello world program, to print something on the console, use print() function.
Output:
That's is the hello world program.
Now you can modify this program as yourself.
Variables:
Var:
To declare any variable you can use var keyword.
you can put any type of data, like, Int, Double, String or anything
If you don't specify the value by default it considers as null
dynamic
You can use another keyword available name dynamic.
this dynamic type of variables can also hold any type of data, like var
You can also specify the data type of the data
Multiple variables:
You can also initialize multiple variables at the same time.
also, you can specify the value
final and const:
If you need a variable that's value is not change after the declaration, use final keyword
also the option for specific variables
If you need runtime constant variables, then use const keyword
specific variable
Lest see an example-
Here, [] create an empty list. and const[] creates an empty immutable list, it's denoted as (EIL)
In the above code,
foo => foo is currently an EIL.
bar => bar will always be an EIL.
baz => baz is a compile-time constant EIL.
It is possible to change the value of a non-final, non-const variable,
even if it used to have a const value.
It is not possible to change the value of a final or const variable.
that's it of the variable.
Comments:
single line comment: as usual like other languages. use '//'
multiline comment:
That's the ending of today post.
Today in this article, I covered Hello world program and variable and Comments.
Thank you for reading.
Happy coding.
The is the first post about Dart
From today I am starting Dart language tutorial.
I already posted a brief introduction about dart and I also try to answer why you choose the dart programming. Check this Dart Introduction
In the previous post, I write about some important concept about dart. Before starting I recommend for taking a look.
Main method:
First, see the code:
void main(List<String> lists) { }
void main() {
}
So, That's so simple.
Now write a hello world program, to print something on the console, use print() function.
void main(List<String> lists) { print("Hello world"); }
Hello world
That's is the hello world program.
Now you can modify this program as yourself.
Variables:
Var:
To declare any variable you can use var keyword.
var v = 10;
var string = "String"; var int = 10; var double = 30.0; var boolean = false;
If you don't specify the value by default it considers as null
var value; //value is null
dynamic
You can use another keyword available name dynamic.
dynamic s = "s";
dynamic string = "String"; dynamic int = 10; dynamic double = 30.0; dynamic boolean = false;
You can also specify the data type of the data
String value; int number; double number2; bool status;
Multiple variables:
You can also initialize multiple variables at the same time.
var a,b,c,d,e;
var a1 = 10,b2 = 20,c2 = 30;
final and const:
If you need a variable that's value is not change after the declaration, use final keyword
final name = "Shudipto";
final String type = "Student"; //explicitly
If you need runtime constant variables, then use const keyword
const value = 1000;
const String data = "data:$value";
Lest see an example-
var foo = const []; final bar = const []; const baz = const [];
In the above code,
foo => foo is currently an EIL.
bar => bar will always be an EIL.
baz => baz is a compile-time constant EIL.
It is possible to change the value of a non-final, non-const variable,
even if it used to have a const value.
foo = [];
It is not possible to change the value of a final or const variable.
// bar = []; // Unhandled exception. // baz = []; // Unhandled exception.
that's it of the variable.
Comments:
single line comment: as usual like other languages. use '//'
//single line comment
multiline comment:
/* * multi line comment */
That's the ending of today post.
Today in this article, I covered Hello world program and variable and Comments.
Thank you for reading.
Happy coding.
No comments :