Dart 基础(摸石头)

2019-06-25  本文已影响0人  iOS_July
T1、重要概念:

T2、Keywords(关键字):
key

T3、Variables(变量):
T4、Default value(默认值):
int lineCount;
assert(lineCount == null);
// Variables (even if they will be numbers) are initially null.

注意: 在生产模式 assert() 语句被忽略了。在检查模式 assert(*condition*) 会执行,如果条件不为 true 则会抛出一个异常。详情请参考 Assert部分。

T5、Optional types(可选的类型):

注意: 对于局部变量,这里准守 代码风格推荐 部分的建议,使用 var 而不是具体的类型来定义局部变量。

T6、Final and const:
final name = 'Bob'; // Or: final String name = 'Bob';
// name = 'Alice';  // Uncommenting this causes an error
const bar = 1000000;       // Unit of pressure (dynes/cm2)
const atm = 1.01325 * bar; // Standard atmosphere
// Note: [] creates an empty list.
// const [] creates an empty, immutable list (EIA).
var foo = const [];   // foo is currently an EIA.
final bar = const []; // bar will always be an EIA.
const baz = const []; // baz is a compile-time constant EIA.

// You can change the value of a non-final, non-const variable,
// even if it used to have a const value.
foo = [];

// You can't change the value of a final or const variable.
// bar = []; // Unhandled exception.
// baz = []; // Unhandled exception.
上一篇 下一篇

猜你喜欢

热点阅读