.toString()
Published May 10, 2024
Contribute to Docs
In Dart, the .toString()
method converts the object into a string representation.
Syntax
typeObject.toString()
Above, typeObject.toString()
calls the toString()
method on the object typeObject
.
Example
The following example demonstrates how the .toString()
method is used to convert numbers to a string:
void main() {int numbers = 123;var result = numbers.toString();print(result);}
The code shown above will generate the following output:
123
Note: The output
123
is a string. This can be confirmed by checkingresult is String
andresult.runtimeType
.
Contribute to Docs
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.