import 'dart:math';
void main() {
print(initSome());
}
initSome() {
var name = "hi";
var age = 18;
var hight = 1.70;
dynamic value = 18;
value = "1";
Object temp = "1";
print("$value");
print(value == temp);
var temp1;
print(temp1);
Person p = Person("ada");
p.name = "112";
print("${p.name}");
String str2 = """Hi,Bruce
12323
ooo
This is Xiaoming.
""";
var a = true;
var arr = ["1", "2", "3"];
var maps = {
"1": "1s",
"2": "1s",
"3": 1,
};
print(arr[1]);
print(maps["2"]);
print(maps.length);
print("\u{1f600}");
Runes input = new Runes("\u{1f600} \u{1f600} \u{1f600}");
print(String.fromCharCodes(input));
shoDesc("Bruce", (name) {
print("name = $name");
});
showDesc1("ada");
Wrold wrold = Wrold(name);
var names = wrold?.name; //先判断p是否为null,如果是,则name为null;如果否,则返回p.name值
print(names);
var num = 10;
var resutlt = num ~/ 3; //得出一个小于等于(num/3)的最大整数
print(resutlt);
var name1;
var name2 = name1 ?? "123"; //如果name1不为null,则name2值为name1的值,否则值为123
print(name2);
Banane(20, "red") //..的使用,级联操作
..showWeight()
..showColor();
/**
* if and else
for循环
while和do-while循环
break和continue
switch-case语句
*/
if (num == 10) {
print("1");
} else {
print("0");
}
for (var i = 0; i < 10; i++) {
print(i);
}
try {
testException();
} catch (e) {
print(e);
}
//类
Tree t = Tree.init();
Tree t1 = new Tree("test111");
print(t.desc);
print(t1.desc);
Apple();
Apple.desc("say hello");
Apple1 atemp = Apple1();
atemp.log(); ////可执行从LogUtil继承过来的方法
//===================
//泛型
FruitFactory<Banana> f = FruitFactory();
Banana ab = f.produceFutit(Banana("a banana"));
ab.log();
FruitFactory<Bjc> f1 = FruitFactory();
Bjc abc = f1.produceFutit(Bjc("a bjc"));
abc.log();
return "1";
}
void shoDesc(var name, Function age) {
age(name);
}
class Person {
static const desc = "23";
var name;
Person(this.name);
}
String getname() {
return "1";
}
void showDesc1(var name) {
print("that is a nested function!");
void println(var name) {
print("name=$name");
}
print(name == "ada" ? "ada1" : "fial");
println(name);
}
class Wrold {
var name = "1";
Wrold(this.name);
}
//as的使用,as用来做类型转化
//判断对象是否为XX类 b is Apple
class Banane {
var weight;
var color;
Banane(this.weight, this.color);
void showWeight() {
print("weight=$weight");
}
void showColor() {
print("color=$color");
}
}
void testException() => throw "exception";
class Tree {
var desc;
Tree.init() {
desc = "this is a seed";
}
Tree(var des) : desc = des;
}
class Fruit {
Fruit() {
print("this is fruit");
}
Fruit.desc(var desc) {
print("$desc");
}
}
class Apple extends Fruit {
Apple() : super() {
print("is it");
}
Apple.desc(var desc) {
print("$desc");
}
}
class LogUtils {
void log() {
print("this is a log");
}
}
class Fruit1 {
Fruit1() {
print("this is furit1");
}
}
class Apple1 extends Fruit1 with LogUtils {
Apple1() : super() {
print("this is apple");
}
}
class Bjc {
var desc;
Bjc(this.desc);
void log() {
print("${this.desc}");
}
}
class Banana {
var desc;
Banana(this.desc);
void log() {
print("${this.desc}");
}
}
class FruitFactory<T> {
T produceFutit(T t) {
return t;
}
}
Dart语法记录
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 表结构 要求:请用一条sql语句统计出下面结果(优秀条件不低于80分) SQL语句: SELECT `type`,...
- 简介: 学习东西,一定要养成知识整理的习惯。再简单的知识,堆积多了,也可能会忘记。今天给大家推荐一个标记语言Mar...