当前位置: 首页 > 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.huolong8.cn/news/115561/

相关文章:

  • 做网站主流网站合肥网红打卡地
  • 怎么做网站跳转江苏seo
  • 怎么做简单的钓鱼网站公司做网站需要什么条件
  • 怎么建设游戏平台网站网设科技
  • 中国免费最好用建站cms谷歌seo营销
  • 知名网站建设是哪家便宜软件ui设计教程
  • 兰州电商平台网站建设网站建设推广费计入什么科目
  • 莱西市建设局网站线上课程
  • 网站上的支付链接该怎么做网站建设一般需要什么功能
  • 网站建设效果图新浪网页版
  • 营销网络什么是seo文章
  • 教做缝纫的网站seo搜索引擎优化视频
  • 品牌建设与营销的关系网站如何优化关键词
  • 如何做好网站建设的设计布局wordpress 子类
  • 响应式网站制作方法ICP网站忘记密码
  • 网站背景音乐长沙网站se0推广优化公司
  • 手机网站制作织梦网站模板保定商城网站建设
  • 什么什么云用来做网站建设营销型网站的步骤
  • 网站域名过期不续费北京网页制作设计企业
  • 国产做的视频网站负责网站建设推广
  • 摄影协会网站源码网站标题写什么作用是什么
  • 广汉网站建设ghxhwl上海微网站开发
  • 网站一键生成手机网站深圳城建局
  • 手机网站使用微信支付wordpress虚拟资源交易平台
  • 长沙响应式网站设计有哪些app制作教程课件
  • 建一个营销网站多少钱网站主题风格有哪些
  • 阜宁网站制作服务商全国哪个县网站做的最好
  • 石家庄网站建设招商怎样建淘宝客网站
  • 网站备案需要什么条件网站建设基本完成
  • 民宿网站开发dfd图网站设计背景怎么写