Basics of dart

And a variable data type

    1, the method defined variables: var variable name; var variable name = **; variable name data type; *** = variable name data type;

    2, the basic data types:

         int: integer type, (var a = 1; or int a = 1;)

   double: float type, (var a = 1.1; or double a = 1.1;)

         num: integer type can also be a floating point type (num a = 1.1)

    String: string type (var name = "Xiaoming"; or  String name = 'Xiaoming'; )

          Strings can ¥ symbols splicing with another data type ( String STR = "$ A = A"; or CC = '$ {} BB'; )

     length: length of the string View (int b = a.length)

         bool: Boolean type, only two values, false and true

         List: list type (var a = [1,2,3,4]; or List a = [1,2, 'qq', 1.2]), which can put a list of data types other data types

    Performed by an index value, starting from 0: var = List Element [ 0];

    length: length of the list view, i.e. several elements ( int length = List.length; )

    If you want to save the data of a data type, it must rely on the generic ( List < String> list3 = < String> [ 'A', 'B', 'C']; ) will be given a different data type

         Map: corresponds dictionary type ( map Map = { 'the Apple': 'apple', 'Banana': 'banana', 'Peach': 'Peaches', . 1: '. 1', to true: 0}; )

               The key value ( String value = Map [ 'the Apple']; )

         Map key and data type values may also be specified ( Map < int, String> Map = < int, String> { . 1: 'A', 2: 'B', . 3: 'C'}; ) if the discharge the other data types will error

Two, if determined

     

var year = 18;
Single determination:
if (year>=20){
    print ( 'large');
  }

Analyzing branched bis
if (year>=20){
    print ( 'large');
  }else{
    print ( 'small');
  }

Multivessel judgment
if (year > 20) {
    print ( 'large');
  } else if (year == 18) {
    print ( 'right');
  }else{
    print ( 'small');
  } 

Third, the loop;

for (var object in flybyObjects) {
  print(object);
}

for (int month = 1; month <= 12; month++) {
  print(month);
}

while (year < 2016) {
  year += 1;
}

Fourth, the function

int test(int n){
  if (n>0){return n;}else{
    return -1;
  }
}

Fifth, the import module

// Importing core libraries
import 'dart:async';
import 'dart:math';

// Importing libraries from external packages
import 'package:angular2/angular2.dart';

// Importing files
import 'path/to/my_other_file.dart';

Sixth, practice

// import 'dart:io';
int test(int n){
  if (n>0){return n;}else{
    return -1;
  }
}
var name="fang";
var year=18;
var bot=4.10;
var li = [name,year,bot];
void main() {
  print (li);
  
  if (year>=20){
    Print ( 'large' );
  }else{
    Print ( 'small' );
  }
  the var 'aa;
  aa=test(0);
  print(aa);
  
  for (var i in li){
    print(i);
  }
  
  for (int i =1;i<10;i++){
    var aa ='';
    for (int j = i;j<10;j++){
      var bb=i*j;
      var cc;
      if (bb > 9){
        cc = '$ {b}' ;
      }else{
        cc = '$ {b}' ;
      }
      aa = '${aa} ${i}*${j}=${cc}';
      
    }
    int a=aa.length;
    print(a);
//     print(aa);
  }
  
  print(11%2);
  
  for (var i=1;i<101;i++){
    if (i%2==0){
      print(i);
    }
  }
  for (var i=1;i<101;i++){
    if (i%2==1){
      print(i);
    }
  }
}
View Code

 

Guess you like

Origin www.cnblogs.com/fangjie0410/p/11496641.html