Skip to content

[Term Entry] Dart Type Conversion .toString() #4598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
May 10, 2024
46 changes: 46 additions & 0 deletions content/dart/concepts/type-conversion/terms/toString/toString.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
Title: '.toString()'
Description: 'Converts the object into a string representation.'
Subjects:
- 'Code Foundations'
- 'Computer Science'
- 'Mobile Development'
Tags:
- 'Dart'
- 'Data Types'
- 'Method'
- 'Strings'
CatalogContent:
- 'learn-dart'
- 'paths/computer-science'
---

In Dart, the **`.toString()`** method converts the object into a string representation.

## Syntax

```pseudo
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:

```dart
void main() {
int numbers = 123;
var result = numbers.toString();
print(result);
}
```

The code shown above will generate the following output:

```shell
123
```

> **Note:** The output `123` is a string. This can be confirmed by checking `result is String` and `result.runtimeType`.