Dart Duration hashCode
Syntax & Examples
Duration.hashCode property
The `hashCode` property in Dart returns the hash code for this object.
Syntax of Duration.hashCode
The syntax of Duration.hashCode property is:
int hashCode
This hashCode property of Duration the hash code for this object.
Return Type
Duration.hashCode returns value of type int
.
✐ Examples
1 Duration with days and hours
In this example,
- We create a Duration object
duration
with 5 days and 12 hours. - We use the
hashCode
property to get its hash code. - We then print the result to standard output.
Dart Program
void main() {
Duration duration = Duration(days: 5, hours: 12);
int hash = duration.hashCode;
print('Hash code: $hash');
}
Output
Hash code: 513922917
2 Duration with seconds
In this example,
- We create a Duration object
duration
with 30 seconds. - We use the
hashCode
property to get its hash code. - We then print the result to standard output.
Dart Program
void main() {
Duration duration = Duration(seconds: 30);
int hash = duration.hashCode;
print('Hash code: $hash');
}
Output
Hash code: 30000000
3 Duration with hours and minutes
In this example,
- We create a Duration object
duration
with 3 hours and 20 minutes. - We use the
hashCode
property to get its hash code. - We then print the result to standard output.
Dart Program
void main() {
Duration duration = Duration(hours: 3, minutes: 20);
int hash = duration.hashCode;
print('Hash code: $hash');
}
Output
Hash code: 333035819
Summary
In this Dart tutorial, we learned about hashCode property of Duration: the syntax and few working examples with output and detailed explanation for each example.