Dart List runtimeType
Syntax & Examples
Syntax of List.runtimeType
The syntax of List.runtimeType property is:
Type runtimeType
This runtimeType property of List a representation of the runtime type of the object.
Return Type
List.runtimeType returns value of type Type
.
✐ Examples
1 Get runtime type of a number
In this example,
- We create a variable
number
with a numeric value. - We then use the
runtimeType
property to get its runtime type. - We print the runtime type to standard output.
Dart Program
void main() {
var number = 42;
var type = number.runtimeType;
print('Runtime type of number: $type');
}
Output
Runtime type of number: int
2 Get runtime type of a character
In this example,
- We create a variable
character
with a character value. - We then use the
runtimeType
property to get its runtime type. - We print the runtime type to standard output.
Dart Program
void main() {
var character = 'A';
var type = character.runtimeType;
print('Runtime type of character: $type');
}
Output
Runtime type of character: String
3 Get runtime type of a list
In this example,
- We create a variable
list
containing integers. - We then use the
runtimeType
property to get its runtime type. - We print the runtime type to standard output.
Dart Program
void main() {
var list = [1, 2, 3];
var type = list.runtimeType;
print('Runtime type of list: $type');
}
Output
Runtime type of list: List<int>
Summary
In this Dart tutorial, we learned about runtimeType property of List: the syntax and few working examples with output and detailed explanation for each example.