Skip to content

Commit b68ba4b

Browse files
Vizhou19achur00
authored andcommitted
[Term Entry] Dart Type Conversion .toString() (Codecademy#4598)
* First Commit for toString() dart * Update toString.md * minor changes * Updated toString.md ---------
1 parent 1978938 commit b68ba4b

File tree

1 file changed

+46
-0
lines changed
  • content/dart/concepts/type-conversion/terms/toString

1 file changed

+46
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---
2+
Title: '.toString()'
3+
Description: 'Converts the object into a string representation.'
4+
Subjects:
5+
- 'Code Foundations'
6+
- 'Computer Science'
7+
- 'Mobile Development'
8+
Tags:
9+
- 'Dart'
10+
- 'Data Types'
11+
- 'Method'
12+
- 'Strings'
13+
CatalogContent:
14+
- 'learn-dart'
15+
- 'paths/computer-science'
16+
---
17+
18+
In Dart, the **`.toString()`** method converts the object into a string representation.
19+
20+
## Syntax
21+
22+
```pseudo
23+
typeObject.toString()
24+
```
25+
26+
Above, `typeObject.toString()` calls the `toString()` method on the object `typeObject`.
27+
28+
## Example
29+
30+
The following example demonstrates how the `.toString()` method is used to convert numbers to a string:
31+
32+
```dart
33+
void main() {
34+
int numbers = 123;
35+
var result = numbers.toString();
36+
print(result);
37+
}
38+
```
39+
40+
The code shown above will generate the following output:
41+
42+
```shell
43+
123
44+
```
45+
46+
> **Note:** The output `123` is a string. This can be confirmed by checking `result is String` and `result.runtimeType`.

0 commit comments

Comments
 (0)