Dart: Built-in types

  1. numbers
  2. strings
  3. booleans
  4. lists (also known as arrays)
  5. maps
  6. runes (for expressing Unicode characters in a string)
  7. symbols

1. Numbers
มี int และ double

บรรทัดที่ 3 : กำหนดค่าเป็นเลขฐาน 16

จะได้

การ parse จาก string เป็น number

การ parse จาก number เป็น string

บรรทัดที่ 7 : กำหนดทศนิยม 2 ตำแหน่ง

การทำ bitwise operators
shift (<<, >>)
AND (&)
OR (|)

 

2. Strings
การใช้ quote และ double quote

การใช้ $s , ${s} , ${s.toSomeThing()}

การต่อ strings

multi-line string ด้วย triple quote
ใช้ได้ทั้ง single quote หรือ double quote
แต่สำคัญว่าช่องว่าง และการเคาะบรรทัดมีผลกับข้อความ

จะได้

“raw” string

บรรทัดที่ 2 : s1 เป็น string ธรรมดา
บรรทัดที่ 3 : s2 เป็น raw string เพราะมี r อยู่ด้านหน้า

จะได้

 

3. Booleans

 

4. Lists
list หรือ array

 

5. Maps
เป็น keys และ values

จะได้

กำหนดค่าแบบนี้ก็ได้

ใช้ทั้ง 2 แบบด้านบนร่วมกันก็ได้

จะได้

การอ่านค่า ถ้าอ่านค่าที่ไม่มีอยู่จริง จะได้ null

หาจำนวนของ key-value pairs ใน map ด้วย .length

ใช้ map แบบ const

 

6. Runes
In Dart, runes are the UTF-32 code points of a string.
Dart string is a sequence of UTF-16 code units, expressing 32-bit Unicode values within a string requires special syntax.
Unicode code point is \uXXXX.

จะได้

การ reverse a string

จะได้

จะเห็นได้ว่าบรรทัดที่ 2 ผิด แต่ก็มีวิธีแก้คือบรรทัดที่ 3 ถูกต้อง
แต่จะเห็นได้ว่าบรรทัดที่ 5 accent อยู่ผิดที่
อันนี้ยังเป็นปัญหาอยู่ ดูได้ที่ How do I reverse a String in Dart?

 

7. Symbols
A Symbol object represents an operator or identifier declared in a Dart program. You might never need to use symbols, but they’re invaluable for APIs that refer to identifiers by name, because minification changes identifier names but not identifier symbols.

To get the symbol for an identifier, use a symbol literal, which is just # followed by the identifier:

 

Link