Catalog

brief introduction

Like all programming languages ,dart There are built-in language types , These built-in types inherit from Object, Of course, these built-in types are dart The basis of language , Only by mastering these built-in types can we use dart Language is handy .

Let's talk about it today dart The built-in type of language .

Null

stay dart of use null To represent null . that null and Null What does it matter ？

Null Is a class , Let's take a look at Null The definition of ：

``````class Null {
factory Null._uninstantiable() {
throw UnsupportedError('class Null cannot be instantiated');
}
external int get hashCode;
/** Returns the string `"null"`. */
String toString() => "null";
}
``````

You can see Null Type of string It means null. And the corresponding null It's a keyword , It corresponds to Null class .

Numbers

dart The corresponding class of numbers in is num, He has two subcategories , Namely int and double.

int No greater than 64 bits The integer of . because dart Can run on different platforms , Therefore, the scope represented by different platforms is also different .

On native platform , such as android perhaps IOS platform ,int It can reach -2^63 To 2^63 - 1. But in web Environment , The representable range is -2^53 To 2^53 - 1.

double The corresponding represents the floating point type .

For numbers , The basic operators are like +, -, / and * It's all defined in num Class . Of course, there are other regular operators .

If more complex operations are needed , You can use dart:math library .

Here are some examples of the use of numbers ：

``````int age =18;
int number= 20;
double money = 10.1;
``````

character string

String is a type that is often used .dart The class corresponding to the string in is String. It can also be expressed directly in literal terms as follows ：

``````var name ='jack';
var site ="www.flydean.com";
``````

Strings can be expressed in single or double quotation marks .dart The string in is UTF-16 code .

dart In the string in , You can also bring variable values , His format is \${expression}.

``````var age=10;
var words ='your age is \${age}!';
``````

Two strings can be used == To see if it's equal , The character comparison is the corresponding character coding sequence , If the character encoding sequences are equal , Then the corresponding strings are equal .

String connection can use +.

``````var hello ="hello " + "word";
``````

Another way to create a string is to use three single quotes or three double quotes .

``````var string1= '''
this is a string!
''';
var string2 = """
this is string again!
""";
``````

By default string The character representation in is the character itself , If you want to convert it to its original meaning , You can prefix the string with r：

``````var string3 =r'this is line one \n this is line two';
``````

Boolean value

Boolean values are in dart of use bool To express .bool The value is only represented by two strings , Namely true and false.

because dart It's type safe , That is, when you need to use bool When it comes to type , No other type can replace .

For example, we need to determine whether the string is empty , It can be judged that ：

``````var name='';
if(name.isEmpty){
do something
}
``````

list

dart The list in... Is used List To express , Of course, you can also directly use the following literal to express ：

``````var list = [1, 2, 3];
``````

List index from 0 Start , With length-1 end .

from dart 2.3 Start , The extension character is introduced ... And nullable extenders ...? , The extender can be used to put a known list Expand to its corresponding element , Thus, it is convenient to build list The combination of ：

``````var list = [1, 2, 3];
var list2 = [0, ...list];
``````

dart Provides a very magical function , Is that you can build list Used in the process of if and for sentence , To generate dynamically list The elements in ：

``````var nav = [
'Home',
'Furniture',
'Plants',
if (promoActive) 'Outlet'
];
``````

perhaps ：

``````var listOfInts = [1, 2, 3];
var listOfStrings = [
'#0',
for (var i in listOfInts) '#\$i'
];
``````

set and map

dart The set in is used Set To express .

set Represents a collection of non repeating elements , As shown below ：

``````var names = {'jack', 'mark', 'max'};
``````

dart The mapping in Map To express .

Map The creation and set Is very similar , But it includes key and value：

``````var students = {'jack':18, 'mark':19, 'max':20};
``````

You can see ,set and map It's very similar , So here comes the question , How to express an empty set perhaps map Well ？

because set The elements in are single , and map The element in is a key value pair , So we can say ：

``````var names = <String>{};
``````

But if you don't specify the type , Then the default is to create a map：

``````var map = {};
``````

To get map The value in , It can be used in this way ：

``````var gifts = Map<String, String>();
``````

map and set All support extensions ... And nullable extensions ...? , It also supports if and for operation .

The most popular interpretation , The deepest dry goods , The most concise tutorial , There are so many tricks you don't know about waiting for you to discover ！

Welcome to my official account. :「 Program those things 」, Know technology , Know you better ！

dart Series of :dart More articles on built-in types in the language

1. Docs-.NET-C#- guide - Language reference - keyword - Built in type - Value type ： Integer numeric type

ylbtech-Docs-.NET-C#- guide - Language reference - keyword - Built in type - Value type : Integer numeric type 1. Return to the top 1. Integer numeric type (C# Reference resources ) 2019/10/22 “ Integer numeric type ” yes “ Simple type ” Of ...

2. Docs-.NET-C#- guide - Language reference - keyword - Built in type - Value type ： Function of value type

ylbtech-Docs-.NET-C#- guide - Language reference - keyword - Built in type - Value type : Function of value type 1. Return to the top 1. Value type (C# Reference resources ) 2018/11/26 There are two value types : structure enumeration The primary value of the value type ...

3. C++ x86 Procedure and x64 In the program , Size comparison of various built-in types

Code : #include <iostream> #include <cstdio> #include <list> #include <string> ...

4. Easily overlooked Python Built in type

Python The built-in types in are the most common in our development , Many people can use them skillfully . However, there are some built-in types that are really less common , Or we often ignore , So the theme of this time is to lead you to re understand these " extraordinary &quo ...

5. Python Built in type ——set

Python in , Built in type set and frozenset Used to represent a collection , Let's first look at the special objects supported by these two types , So we can understand their characteristics . >>> dir(set) ['__and__', '_ ...

6. Dart Based on learning 02-- Variables and built-in types

Dart Based on learning 02-- Variables and built-in types Dart The variables in the First look at the definition and assignment of a variable var name = 'Bob'; stay Dart Variable names in are all references , there name Is a point with a value of Bob A reference to a string ...

7. C++ Overloading in language 、 inline 、 Default parameters 、 Mechanisms such as implicit conversion show many advantages

C++ Overloading in language . inline . Default parameters . Mechanisms such as implicit conversion show many advantages , But these There are some hidden dangers behind the advantages . Just like people's diet , It's not advisable to eat less or eat too much , It should be just right . We should treat it dialectically C++ The new mechanism of , It should be just like ...

8. By calling C The library function of a language is similar to that in C The code uses two ways of inline assembly to use the same system call to analyze the working mechanism of system call

By calling C The library function of a language is similar to that in C The code uses two ways of inline assembly to use the same system call to analyze the working mechanism of system call Preface explains This is Netease cloud class Linux Homework for the fourth week of kernel analysis , I'll call C The library function of a language is similar to that in C In the code ...

9. Golang Introductory series （ 5、 ... and ）GO Object oriented in language

I've said a lot Go Basic knowledge of language , Include go Installation of environment ,go Language grammar, etc , Interested friends can read the previous article first .https://www.cnblogs.com/zhangweizhong/category/ ...

10. 《WCF Technical analysis 》 Blog series summary [ Ongoing update ]

original text :<WCF Technical analysis > Blog series summary [ Ongoing update ] In the past six months , I've been busy with my first book WCF monograph <WCF Technical analysis ( volume 1)> Writing , I have no time to manage my own Blog. stay <WCF Technology ...

Random recommendation

1. __future__

[__future__] __future__ Used to change python characteristic . Reference resources :http://www.liaoxuefeng.com/wiki/001374738125095c955c1e6d8bb4 ...

2. 《 Safety reference 》HACKCTO-201312-12

What Xiaobian said “ All of a sudden, spring breeze comes , Thousands of trees and thousands of pear blossom .” friends , Don't just “ Pear blossoms of thousands of trees ” And surprise , Be intoxicated ! meanwhile , Your favorite integrated information security technology journal < Safety reference > The first 12 The time has come as promised ! This issue &l ...

3. c++ static Usage Summary 【 Reprint 】

static Keywords are C, C++ Keywords that exist in all .static literally , yes “ Static “ Of Meaning , Corresponding to this , Should be “ Dynamic “. static The main functions of the system are as follows 3 individual : 1. Extended lifetime : 2. Limit scope : ...

4. Use RSA Encrypted in Python In reverse shell

i Spring and autumn translation group -Neo( Li Haowei ) Use RSA Encrypted in Python In reverse shell This is about using RSA Encryption programming reverse shell Of python course . I want to mention , This article is more about understanding shell Involved in the ...

5. 1111. Online Map (30)

Input our current position and a destination, an online map can recommend several paths. Now your jo ...

6. Native javascript Achieve smooth scrolling back to the top

function rt() { var d = document, dd = document.documentElement, db = document.body, top = dd.scroll ...

7. GNU make Use （ Two ）

[ Time :2017-06] [ state :Open] [ key word :makefile,gcc, compile ,shell command , Target file ] 0 Introduction and objectives Before using Makefile Both source and target files are compiled in the same directory . near ...

8. Maven Multiple project dependencies , Need to verify artifact Of output root Whether other project outputs are included in the

9. Android code confusion (Android Studio)

Proguard Android provides convenience for developers to code and apk Tools for protection and streamlining , Can be found in SDK/tools Found under folder .   proguard The role of : 1, Code obfuscation 2, To streamline the code , Delete unused code , Reduce ap ...

10. MySQL The database character set consists of utf8 It is amended as follows utf8mb4 One example is

about mysql 5.5 for , If you don't set the character set ,mysql The default character set is  latin1 Latin character set : For the convenience of unified management and application development , Generally, the operating system will be unified , client , The character set for all aspects of the database is set to ut ...