当前位置: 首页 > news >正文

网站建设销售人员培训教程关于网站建设与维护的心得体会

网站建设销售人员培训教程,关于网站建设与维护的心得体会,深圳定制网站制作招聘网,软文媒体发稿平台文章目录 字符串插值(String interpolation)空变量 null避空运算符条件属性访问集合字面量箭头语法 字符串插值(String interpolation) 下面是一些使用字符串插值的例子#xff1a; Here are some examples of using string interpolation: String result 字符… 文章目录 字符串插值(String interpolation)空变量 null避空运算符条件属性访问集合字面量箭头语法 字符串插值(String interpolation) 下面是一些使用字符串插值的例子 Here are some examples of using string interpolation: String result 字符串 结果 ${3 2} 5 ${word.toUpperCase()} WORD The value of $myObject myObject.toString().小练习 Q: 下面的方法接收两个整型变量作为参数然后让它返回一个包含以空格分隔的整数的字符串。例如stringify(2, 3) 应该返回 ‘2 3’。 A String stringify(int x, int y) {return ${x} ${y} }或者 String stringify(int x, int y) { return ‘KaTeX parse error: Double superscript at position 10: {x} ̲ {y}’; } 空变量 null Dart 要求使用健全的空安全这意味着除非变量显式声明为可空类型否则它们将不能为空。换句话说类型默认是不可为空的。 举个例子下面的代码在空安全下是有错误的因为 int 类型的变量不能为 null int a null; // INVALID.你可以通过在类型后添加 ? 来表示该类型可空 int? a null; // Valid.在所有 Dart 版本中null 在未初始化的变量里都是默认值所以你可以这样简化你的代码 int? a; // The initial value of a is null.Q: 试着定义以下两种变量 一个可空的 String名为 name值为 ‘Jane’。 一个可空的 String名为 address值为 null。 A: String ?name Jane; String ?address ;避空运算符 Dart 提供了一系列方便的运算符用于处理可能会为空值的变量。其中一个是 ?? 赋值运算符仅当该变量为空值时才为其赋值 int? a; // null a ?? 3; print(a); // -- Prints 3.a ?? 5; print(a); // -- Still prints 3.另外一个避空运算符是 ??如果该运算符左边的表达式返回的是空值则会计算并返回右边的表达式。 print(1 ?? 3); // -- Prints 1. print(null ?? 12); // -- Prints 12. String? baz foo ?? bar; // 如果 foo 是 null 才会赋值为 bar条件属性访问 要保护可能会为空的属性的正常访问请在点.之前加一个问号?。 myObject?.someProperty上述代码等效于以下内容 (myObject ! null) ? myObject.someProperty : null你可以在一个表达式中连续使用多个 ?. myObject?.someProperty?.someMethod()如果 myObject 或 myObject.someProperty 为空则前面的代码返回 null并不再调用 someMethod。 Q: 尝试使用条件属性访问来完成下面的代码片段。 // This method should return the uppercase version of str // or null if str is null. String? upperCaseIt(String? str) {// Try conditionally accessing the toUpperCase method here.}A: return str?.toUpperCase() ; // 如果不为空就返回大写字母 集合字面量 Dart 内置了对 list、map 以及 set 的支持。你可以通过字面量直接创建它们 final aListOfStrings [one, two, three]; final aSetOfStrings {one, two, three}; final aMapOfStringsToInts {one: 1,two: 2,three: 3, };Dart 的类型推断可以自动帮你分配这些变量的类型。在这个例子中推断类型是 List、Set和 MapString, int。 你也可以手动指定类型 final aListOfInts int[]; final aSetOfInts int{}; final aMapOfIntToDouble int, double{};在使用子类型的内容初始化列表但仍希望列表为 List 时指定其类型很方便 final aListOfBaseType BaseType[SubType(), SubType()];Q: 尝试将以下变量设定为指定的值。替换当前的 null 值。 // Assign this a list containing a, b, and c in that order: final aListOfStrings null ;// Assign this a set containing 3, 4, and 5: final aSetOfInts null;// Assign this a map of String to int so that aMapOfStringsToInts[myKey] returns 12: final aMapOfStringsToInts null;// Assign this an empty Listdouble: final anEmptyListOfDouble null;// Assign this an empty SetString: final anEmptySetOfString null;// Assign this an empty Map of double to int: final anEmptyMapOfDoublesToInts null;A: // Assign this a list containing a, b, and c in that order: final aListOfStrings [a, b, c];// Assign this a set containing 3, 4, and 5: final aSetOfInts {3, 4, 5};// Assign this a map of String to int so that aMapOfStringsToInts[myKey] returns 12: final aMapOfStringsToInts {myKey: 12};// Assign this an empty Listdouble: final anEmptyListOfDouble double[];// Assign this an empty SetString: final anEmptySetOfString String{};// Assign this an empty Map of double to int: final anEmptyMapOfDoublesToInts double, int{}; 箭头语法 你也许已经在 Dart 代码中见到过 符号。这种箭头语法是一种定义函数的方法该函数将在其右侧执行表达式并返回其值。 例如考虑调用这个 List 类中的 any 方法 bool hasEmpty aListOfStrings.any((s) {return s.isEmpty; });这里是一个更简单的代码实现 bool hasEmpty aListOfStrings.any((s) s.isEmpty);看看下面的代码 class MyClass {int value1 2;int value2 3;int value3 5;// Returns the product of the above values:int get product value1 * value2 * value3;// Adds 1 to value1:void incrementValue1() value1; // Returns a string containing each item in the// list, separated by commas (e.g. a,b,c): String joinWithCommas(ListString strings) strings.join(,); }
http://www.sadfv.cn/news/115561/

相关文章:

  • 关方网站买微信成都市住房和城乡建设厅网站
  • 四川手机响应式网站建设设计网站建设钱
  • 中山网站上排名营销型网站建设+课程
  • 织梦网站自动跳转手机网站做网站怎么宣传运营
  • 视频购物网站开发方案网站建设专业如何做到廉洁自律
  • 网站建设廾金手指专业壹柒太原最新建设
  • 番禺龙美村做网站什么是网站子目录
  • 国内工业设计网站产品开发流程文件
  • 广州品牌网站开发北京怎样做企业网站
  • 阆中 网站建设企业 办公 网站模板下载
  • 东莞网站关键词优化淘宝网站建设的策划书
  • 建筑企业登录建设厅网站密码js代码放wordpress哪里
  • vps 网站权限模板网站建设平台
  • 深圳常桉网站建设网站注册备案查询
  • 凡科小程序建站官网网站备案分为几种
  • 电商网站设计网络服务小型电子商务网站规划建设方案
  • html5 手机端网站wordpress模板如何修改
  • 中山外贸营销网站建设h5页面制作网站官网
  • 做网站可以用php吗个人网页设计概述
  • 合肥建设网站首页网站开发综合实训报告
  • 运城建设银行网站点黄冈网站建设哪家好
  • 做网站用到的单词中国网站空间
  • ih5 做视频网站火车采集器 wordpress
  • php网站开发师中国一级爱做电影网站
  • 淄博网站建设详细策划wordpress素材模板
  • 英文外贸商城网站设计语音网站怎么做
  • 做网站都要掌握什么软件网站升级维护
  • 广西专业网站建设上海做高端网站
  • 做资讯网站需要什么条件wordpress 常用小工具
  • 网站列表页是啥手机改ip地址软件免费