<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                [TOC] ## 變量 ``` var name = 'Bob'; //類型推導出 string 類型 String name = 'Bob'; //顯示聲明 var v1=1; var v2="hello"; var v3=3.3; var v4=true; var v5=[1, 2, 3]; const c1=1; const c2="hello"; const c3=3.3; const c4=true; const c5 = [1, 2, 3]; ``` ### 默認值 未初始化的變量默認值是 null,數字也是null,因為一切皆對象 ``` int lineCount ; assert(lineCount == null); ``` ## Number int * 整數值不大于64位 * 值的范圍從 -263 到 263 - 1 float * 64位(雙精度)浮點數 方法 * abs(), ceil(), 和 floor() ``` //生成整數 var x = 1; var hex = 0xDEADBEEF; //浮點數 var y = 1.1; var exponents = 1.42e5; //從 Dart 2.1 int 必要時會轉為 float double z = 1; // 相當于 double z = 1.0. ``` ### 位運算 ``` assert((3 << 1) == 6); // 0011 << 1 == 0110 assert((3 >> 1) == 1); // 0011 >> 1 == 0001 assert((3 | 4) == 7); // 0011 | 0100 == 0111 ``` ### 字符串,為數字相互轉換 ``` // String -> int var one = int.parse('1'); assert(one == 1); // String -> double var onePointOne = double.parse('1.1'); assert(onePointOne == 1.1); // int -> String String oneAsString = 1.toString(); assert(oneAsString == '1'); // double -> String String piAsString = 3.14159.toStringAsFixed(2); assert(piAsString == '3.14'); ``` ## String UTF-16 單元序列。 字符串通過單引號或者雙引號創建 ``` var s1 = 'Single quotes work well for string literals.'; var s2 = "Double quotes work just as well."; var s3=""" hello word """; var s4 ="hello "+"word"; var s = r"hello \n word"; // \b 不轉義 ``` ### ${expression} 嵌入字符串 ``` var a ="hello"; print('${a} word'); // hello word print("${a} word"); // hello word ``` ## Boolean 不同類型檢查 boo 的方法 ``` // 檢查空字符串。 var fullName = ''; assert(fullName.isEmpty); // 檢查 0 值。 var hitPoints = 0; assert(hitPoints <= 0); // 檢查 null 值。 var unicorn; assert(unicorn == null); // 檢查 NaN 。 var iMeantToDoThis = 0 / 0; assert(iMeantToDoThis.isNaN); ``` ### 創建空集 ``` var names = <String>{}; // Set<String> names = {}; // 這樣也是可以的。 // var names = {}; // 這樣會創建一個 Map ,而不是 Set 。 ``` ### 設置 編譯時常量 ``` final constantSet = const { 'fluorine', 'chlorine', 'bromine', 'iodine', 'astatine', }; // constantSet.add('helium'); // Uncommenting this causes an error. ``` ## Rune Rune 用來表示字符串中的 UTF-32 編碼字符,由于 Dart 字符串是一系列 UTF-16 編碼單元, 因此要在字符串中表示32位 Unicode 值需要特殊語法支持 ``` main() { var clapping = '\u{1f44f}'; print(clapping); print(clapping.codeUnits); print(clapping.runes.toList()); Runes input = Runes( '\u2665 \u{1f605} \u{1f60e} \u{1f47b} \u{1f596} \u{1f44d}'); print(String.fromCharCodes(input)); //ouput //?? // [55357, 56399] // [128079] // ? ?? ?? ?? ?? ?? } ``` ## 枚舉類型 ``` enum Color { red, green, blue } //枚舉都有 getter 犯法 assert(Color.green.index == 1); //枚舉的 values 常量 List<Color> colors = Color.values; assert(colors[2] == Color.blue); var aColor = Color.blue; switch (aColor) { case Color.red: print('Red as roses!'); break; case Color.green: print('Green as grass!'); break; default: // 沒有這個,會看到一個警告。 print(aColor); // 'Color.blue' } ``` ## typedef 聲明一種類型 ``` typedef int Compare(int a, int b); int sort(int a, int b) => a - b; main() { print(sort is Compare); //true } ```
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看