Dart String runtimeType
Syntax & Examples
Syntax of String.runtimeType
The syntax of String.runtimeType property is:
Type runtimeType
This runtimeType property of String returns the representation of the runtime type of the object.
Return Type
String.runtimeType returns value of type Type
.
✐ Example
1 Get runtime type of a string
In this example,
- We create a string
str1
with the value 'Hello, world!'. - We then access the
runtimeType
property ofstr1
to get its runtime type. - The runtime type of
str1
is printed to standard output.
Dart Program
void main() {
String str1 = 'Hello, world!';
Type type1 = str1.runtimeType;
print('Runtime type of str1: $type1');
}
Output
Runtime type of str1: String
Summary
In this Dart tutorial, we learned about runtimeType property of String: the syntax and few working examples with output and detailed explanation for each example.