Course Content
Introduction to Dart
Introduction to Dart
Properties of Numbers
We already know about int
and double
. This сhapter will teach how to work with these data types.
What are Properties?
In programming, just like in our life, things have their properties. It applies to all things. The properties of cars include brand, maximum speed, engine capacity, etc. The book properties include the author, genre, and number of pages.
To find out what is stored in the property, you need:
Properties of int
isEven
:
This property stores a bool
value about whether the number is even or not. If the number is even, true
is stored in the property. If it is negative, then false
.
main
void main(){ int number = 2; print(number.isEven); // `true` }
We don't need to program to know that 2 is even. But if the result in the variable stores the result of a mathematical expression, the properties will be beneficial to learn more.
main
void main(){ int result = 2 * -3 * -3 + 13 + 31 * -3 * 31; print(result.isEven); // `true` or `false` ? }
The computer calculated the expression (result = -2852). The number is even.
isNegative
:
We will get true
if the number is negative. If the number is positive or 0, we will get false
.
main
void main(){ int number = 4; print(number.isNegative); // `false` }
All the properties listed above are properties of the int
type. These properties are not present in other data types (even in double
, although they are also numbers).
Every data type has its own properties, and you will get acquainted with them eventually. But at this stage, it's crucial to understand that all data types are different, and each one requires its own approach.
Thanks for your feedback!