dart中的关键字

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/coderinchina/article/details/91416374

我们知道任何一门语言都会有它自己的一套关键词,这个在定义变量的时候是不能使用的,那么在dart中有哪些关键词呢?看官网文档给出的

我们发现有的关键词右上角有数字是什么意思呢?我们把文档看明白就知道了

Avoid using these words as identifiers. However, if necessary, the keywords marked with superscripts can be identifiers:

Words with the superscript 1 are contextual keywords, which have meaning only in specific places. They’re valid identifiers everywhere.

Words with the superscript 2 are built-in identifiers. To simplify the task of porting JavaScript code to Dart, these keywords are valid identifiers in most places, but they can’t be used as class or type names, or as import prefixes.

Words with the superscript 3 are newer, limited reserved words related to the asynchrony support that was added after Dart’s 1.0 release. You can’t use await or yield as an identifier in any function body marked with async, async*, or sync*.

All other words in the table are reserved words, which can’t be identifiers

第一行解释:

避免使用这些单词作为标识符。但是,如果需要,用上标标记的关键字可以是标识符

例子:

void main() {
  var set = const [1,2,3];
  print(set);
}

发现set虽然是关键词但是我们使用set声明称一个变量也是可以的,而if关键词是没有打标记的 是不能当作变量名的

标记1 的作用先看翻译文档:

上标1的单词是上下文关键字,只有在特定的地方才有意义。它们到处都是有效标识符

标记2的作用翻译文档:

带有上标2的单词是内置标识符。为了简化将JavaScript代码移植到Dart的任务,这些关键字在大多数地方都是有效的标识符,但是它们不能用作类或类型名,也不能用作导入前缀

标记3的作用翻译文档:

带有上标3的单词是较新的、有限的保留单词,它们与Dart 1.0发行版之后添加的异步支持相关。不能在任何用async、async*或sync*标记的函数体中使用wait或yield作为标识符

这些我们边开发边记住就行!

猜你喜欢

转载自blog.csdn.net/coderinchina/article/details/91416374