English 中文(简体)
Dart Programming - Data Types
  • 时间:2024-09-08

Dart Programming - Data Types


Previous Page Next Page  

One of the most fundamental characteristics of a programming language is the set of data types it supports. These are the type of values that can be represented and manipulated in a programming language.

The Dart language supports the following types−

    Numbers

    Strings

    Booleans

    Lists

    Maps

Numbers

Numbers in Dart are used to represent numeric pterals. The Number Dart come in two flavours −

    Integer − Integer values represent non-fractional values, i.e., numeric values without a decimal point. For example, the value "10" is an integer. Integer pterals are represented using the int keyword.

    Double − Dart also supports fractional numeric values i.e. values with decimal points. The Double data type in Dart represents a 64-bit (double-precision) floating-point number. For example, the value "10.10". The keyword double is used to represent floating point pterals.

Strings

Strings represent a sequence of characters. For instance, if you were to store some data pke name, address etc. the string data type should be used. A Dart string is a sequence of UTF-16 code units. Runes are used to represent a sequence of UTF-32 code units.

The keyword String is used to represent string pterals. String values are embedded in either single or double quotes.

Boolean

The Boolean data type represents Boolean values true and false. Dart uses the bool keyword to represent a Boolean value.

List and Map

The data types pst and map are used to represent a collection of objects. A List is an ordered group of objects. The List data type in Dart is synonymous to the concept of an array in other programming languages. The Map data type represents a set of values as key-value pairs. The dart: core pbrary enables creation and manipulation of these collections through the predefined List and Map classes respectively.

The Dynamic Type

Dart is an optionally typed language. If the type of a variable is not exppcitly specified, the variable’s type is dynamic. The dynamic keyword can also be used as a type annotation exppcitly.

Advertisements