Unluckily today, the internet was disconnected. After learning half of it, the language is similar to java.
/* Dart 命名规则:
1:变量名称必须由数字,字母,下划线和美元符($)组成;
2:注意:标识符开头不能是数字
3:标识符不能是保留字和关键字
4:变量的名字时区分大小写的 例如:age 和 AGE 是不同变量,在实际运用中,也建议,不要用一个
5:标识符(变量的名称)一定要见名思意:变量名称建议用名词,方法名称建议用动词
*/
// void main() {
// var str1 = '123456';
// print(str1);
//var 2str ='xxx' 错误示例
// var if ='12345';
// }
/*Dart 常量:final 与 const 修饰符
const 值不变 一开始就得赋值
final 可以开始不赋值 只能赋值一次; 而final 不仅有const 的编译时常量的特性
final 特性 运行时常量 并且final 时惰性初始化,即在运行时第一次使用前才初始化
永远不改变的量 请用 final 或const 修饰 而不是使用var 或其他变量类型
*/
void main() {
var str = 'this is str';
str = '2';
print(str);
int num = 0;
num = 8;
print(num);
const PI = 3.14159;
// PI = 12.123;//错误示例
print(PI);
//final 常量
// final PIA = 3.14159;
// // PIA = 12.123;//错误示例
// print(PI);
final date = new DateTime.now();
print(date);
}
//表示 main 方法没有返回值
// void main() {
// print("Hello World!");
// }
/* dart 脚本类语言 可以预先不定义变量类型 自动会类型推断
dart 中的定义变量 可以通过var 关键字 可以通过 类型来申明变量*/
void main() {
// var str = '你好 dart!';
// var num = 1234;
// print(str);
// print(num);
//定义字符串
// String str = '你好 dart';
// print(str);
//数字类型
// int num = 245;
// print(num);
// 类型 定义不可变 报错
// var str = '';
// str = 123;
// print(str);
// String str = 123456;
// print(str); 错误示例
// String str = "123456";
// print(str);
// int num = "112343";
// print(num); 错误示例
}
The net is ready.
* The following types are supported in Dart
* Common data types:
* Numbers: int double
* String (string): String
* Booleans: bool
* List (array): In Dart, an array is a list object. So most people just call them lists
* Maps (dictionary): Generally speaking: Map is an object related to a key-value pair. Keys and values can be any type of object. Each key indicates each value.
String
/* Dart 数据类型:字符串类型*/
void main() {
//1 字符串 定义的几种方式
// var str = 'this is';
// var str1 = "this is dart";
// print(str);
// print(str1);
// String str = 'this is';
// String str1 = "this is dart";
// print(str);
// print(str1);
// String str = '''this
// this
// this ''';
// print(str);
// String str = """this
// this
// this """;
// print(str);
//2字符串的拼接
String str1 = "Hello";
String str2 = "World";
print("$str1 $str2");
print(str1 + str2);
print(str1 + " " + str2);
}
int double
/**
* Dart:数值类型
* int double
*/
void main() {
//1 int 必须是整型
int a = 123;
print(a);
//2 double 既可以是整型 也可以是浮点型
double b = 1.2;
double c = 20;
print(b);
print(c);
//3.运算符
//+ - * / %
var q = a + b;
print(q);
}
bool List
Maps are a bit different to get the key value. The most favorite is, the judgment is simple, and it’s here today
They are all rookie-level things, written in order to check the records in the future. Don't spray if you don't like it, thanks!