当前位置:网站首页>Dart tips
Dart tips
2022-06-30 08:17:00 【yyqx&xxxx】
dart Little knowledge - Dart Is an object-oriented programming language
- var- According to the character
var It can be used to represent many different data types ,int,double,list Both can be used. var Express .
string Types and integers cannot be mixed , Use both var Express , But logic is wrong .
1,final: Assigned once , It can be the object , character string , Numbers etc. , Variable used to modify the expression of a value .
const: Set an explicit value .
2,Boolean Boolean type : Used to judge , The value is true or false.
var sex = true; var sex = false
if(sex){ if(sex){
3,List type ( Array )
- Basic operation : increase , Delete , Change , check
- increase :add
addAll—— Batch addition
insert—— Add... At the specified location insert(n, Number to be added )
insertAll—— Batch add - reduce :remove
remove—— Delete eligible elements
clear—— Delete all elements
removeAt—— Specify location search delete removeAt( Delete , Don't delete ) The principle of moving left and not moving right
*1.start and end Must be effective , The value range is 0 <= start <= end <= length
*2. The removed array cannot be a fixed length array - Change :setRange—— Modify an interval element
setAll—— Modify the italicized elements after searching
replaceRange—— Replace
fillRange—— Replace an interval with a fixed value
getRange—— Get the value of an interval - check :singleWhere
- increase :add
//List<int m = [8, 12, 4, 1, 17, 33, 10];
int a = m.singleWhere((n) => n > 30); //33
int b =m.singleWhere((n) => n > 10); // Report errors
int c = m.singleWhere((n) => n > 10, orElse: () => -1); // Report errors
int d = m.singleWhere((n) => n > 40, orElse: () => -1); //-1
** In the use of singleWhere when , it is to be noted that The following points :
When there is only one element in the array that meets the condition , Return the element
When there are multiple qualified elements in the array , Report errors
When there are multiple qualified elements in the array , Even if it's set orElse , also Will report a mistake
When there is no element in the array that meets the condition , return orElse Specified return value
- subList(n)—— Return from index n After the value of
subList(m,n)—— Return from m To n Value
**any—— Determine whether there are elements in the array that meet the requirements
print(list.any((v) => v > 2));
every—— Determine whether the elements in the array meet the requirements
contains—— Determine whether the array contains an element
4.Map type —— Mapping function
- Define fixed type arrays :List<int ()–List<string ()
Define a fixed length array :List(n)
Define a mixed type array :List<dynamic ()
Define array length :List.length
Array in reverse order :reversed
Determine whether the array is empty :isEmoty
// var list = [1, 2, 3, 4;
print(list.isEmpty); //false;
## Determine whether the array is non empty :isNotEmpty
List[n]=n+1
function and class
function —— By setting the function law , Process the data , To realize a certain function is the function of a programming language .
class —— In object-oriented programming , A function that matches an object .( It's a special function )
- Function return value :
- All functions have return values return
- If the return value of the function is not specified , The default return value is null
- Functions that do not return values , The system will add implicit return sentence
// main(){
bool m(String str1,String str2){
return str1 != str2;
}
String str1="YYQX";
String str2="SXX";
print(m(str1,str2));
}
//main(){
bool m(int a, int b) {
return a == b;
}
int a = 1;
int b = 2;
print(m(a, b));
}
- Optional parameters ——a There are three variables in it :name1,name2,c; among c It's an optional parameter . b Is a string variable ,$ String names can be used to introduce strings . stay c When it's worth it ,b The second half of the sentence will be displayed , On the contrary, it does not show .
// main() {
String a(String name1, String name2, [String c = "YYQX"]) {
var b = '$name1 like $name2';
if (c != null) {
b = '$b like $c';
}
return b;
}
print(a('YYQX', 'SXX'));
}
边栏推荐
- Sword finger offer II 076 The kth largest number in the array (use heap to solve TOPK problem)
- Why don't you know what to do after graduation from university?
- 牛客小白月赛52
- Opencv image
- Experiment 2 LED button PWM 2021/11/22
- Dlib library blink
- Sword finger offer II 075 Array relative sort (custom sort, count sort)
- End-to-end 3D Point Cloud Instance Segmentation without Detection
- Introduction to opencv (I): image reading and display
- 多快好省,低门槛AI部署工具FastDeploy测试版来了!
猜你喜欢

【JUC系列】Fork/Join框架之概览

Game 280 problem2: minimum operands to turn an array into an alternating array

亚马逊测评术语有哪些?

领域驱动下cloud项目中单个服务的示例

Redis design and Implementation (VIII) | transaction

Deep learning - networks in networks and 1x1 convolution

Deep learning - LSTM

Redis 的过期数据如何处理,淘汰机制都有那些?

What management improvements can CRM bring to enterprises
![[nvme2.0b 14-8] set features (Part 2)](/img/fe/67fd4f935237f9aa835e132e696b98.png)
[nvme2.0b 14-8] set features (Part 2)
随机推荐
TP5 set direct download file
Redis设计与实现(一)| 数据结构 & 对象
Deep learning -- sequence model and mathematical symbols
ACM. Hj48 delete the node with the specified value from the one-way linked list ●●
【NVMe2.0b 14-2】Create/Delete Queue
【NVMe2.0b 14-1】Abort、Asynchronous Event Request、Capacity Management command
Construction of module 5 of actual combat Battalion
Experiment 6 examination
Unity 基础光照模型
Unity简单shader
Leetcode47. full arrangement II
[JUC series] overview of fork/join framework
Hit the industry directly | the flying propeller launched the industry's first model selection tool
Tue Jun 28 2022 15:30:29 gmt+0800 (China standard time) date formatting
一次cpu 跌底排查
想问问,炒股怎么选择证券公司?网上开户安全么?
【NVMe2.0b 14-3】Doorbell Buffer Config command、Device Self-test command
Experiment 3 remote control
Pycharm Dlib library installation
Opencv video