Dart 語言

Hello World

void main() {
  print("Hello World!");
}

Output :

Hello World!

註解

/*
我是很長的備註
*/

void main() {
  // 一行備註
  print("Hello World!");
}

保留字

abstract

default

final

null

throw

as

deferred

finally

operator

true

assert

do

for

part

try

async

dynamic

get

rethrow

typedef

await

else

if

return

var

break

enum

implements

set

void

case

export

import

static

while

catch

external

in

super

with

class

extends

is

switch

yield

const

factory

library

sync

continue

false

new

this

變數宣告

變數型別

說明

舉例

bool

Boolean 布林數

true, false

int

整數

1、2、3、4

double

2倍精確度浮點數

1.2、0.0

String

字串

"123"

var

未定型別變數

dynamic

泛型

範例

變數前綴

前綴

說明

舉例

final

不允許再次更改數值

final int i = 0;

const

常數

const double PI = 3.14;

lazy

延遲賦值

lazy var VarABC;

集合宣告

變數名

說明

舉例

List

陣列

List<int> 整數陣列 , List<String> 字串陣列

Map

key-value pairs

Map<String,int> ...

map reduce where filter

null? empty?

Null-Safty

在宣告變數時先講清楚,到底 可不可以為 null。如果可以有null,編譯器就會提早檢查你是否有針對 null 做處理

運算子

少了 ...

賦值

串接

屬性

流程控制

迴圈

for

while

do-while

跳脫

break / continue

判斷式

  • if / elseif / else

  • switch case

函數 / 匿名函數

return value / function parameter / optional parameter / Positional parameter

implements

Exeption

練習區

DartPad : https://dartpad.dev/?null_safety=truearrow-up-right

Last updated

Was this helpful?