在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
Dart编程语言是一个完全面向对象的语言,包括基础类型如int变量也都是对象。 如何定义变量 var name = 'Bob';
变量的初始值 int lineCount; assert(lineCount == null); // Variables (even numbers) are initially null. 可以使用var,也可以直接指定类型。 final, 定义为final的变量,值不能够被更改 final name = 'Bob'; // Or: final String name = 'Bob'; name = 'Alice'; // ERROR 2. 基础类型字符串字符串可以使用单引号或者双引号。 var s1 = 'Single quotes work well for string literals.'; var s2 = "Double quotes work just as well.";
var s = 'string interpolation'; assert('Dart has $s, which is very handy.' == 'Dart has string interpolation, which is very handy.'); assert('That deserves all caps. ${s.toUpperCase()} is very handy!' == 'That deserves all caps. STRING INTERPOLATION is very handy!');
var s = 'String ''concatenation' " works even over line breaks."; assert(s == 'String concatenation works even over line breaks.');
var s1 = ''' You can create multi-line strings like this one. ''';
var s = @"In a raw string, even \n isn't special.";
var sb = new StringBuffer(); sb.add("Use a StringBuffer "); sb.addAll(["for ", "efficient ", "string ", "creation "]); sb.add("if you are ").add("building lots of strings."); var fullString = sb.toString();
|
请发表评论