其他型別語句

2022-08-27 20:36:09 字數 2026 閱讀 8799

分支:switch

switch(表示式)

案例:string s = console.readline();

switch (s)

迴圈:while

初始條件

while(迴圈條件)

案例:int i=0;

while(i<10)

它是從下面演變過來的:

//int i = 0;

//for (; i < 10; )

//foreach 一般用來迴圈遍歷陣列(或集合)的。

用來從頭到尾遍歷,不涉及到下標或計數;而且迴圈過程中,不能修改陣列或集合中的值。

foreach(型別 變數 in 陣列或集合)

陣列:鋸齒陣列 陣列的陣列

一、定義

1.定義陣列的陣列:

int a = new int[3];

2.定義一維陣列:

int a1 = new int[5] ;

int a2 = new int[2] ;

int a3 = new int[3] ;

3.把一維陣列放到陣列的陣列中。

a[0] = a1;

a[1] = a2;

a[2] = a3;

二、操作某個元素:

a[行][列]

for (int i = 0; i < a.length; i++)

console.writeline();

}集合:

陣列與集合的區別:

陣列:同一型別,連續儲存。優點:儲存效率高,檢索速度快。 缺點:連續的,不能擴充套件,不能刪除,不能插入

集合:同一型別,不連續儲存。

集合的操作:——arraylist是集合中的一種

一、鍊錶

弱型別的集合:

arraylist list = new arraylist();

新增操作:list.add(值);

插入操作:list.insert(下標,值)

刪除操作:list.removeat(下標)

清空集合:list.clear()

獲得集合中元素個數:int n = list.count;

獲取某個值:object n = list[下標];

強型別的集合:

list《型別》 集合名 = new list《型別》();

新增操作:list.add(值);

插入操作:list.insert(下標,值)

刪除操作:list.removeat(下標)

清空集合:list.clear()

獲得集合中元素個數:int型名 n = list.count;

二、雜湊表:

弱型別hashtable list = new hashtable();

新增操作:list.add("名","值");

刪除操作:list.remove("名");

清空集合:list.clear()

獲得集合中元素個數:int n = list.count;

獲取值: object n = list["名"];

強型別:

dictionarytable = new dictionary();

新增操作:list.add("名","值");

刪除操作:list.remove("名");

清空集合:list.clear()

獲得集合中元素個數:int n = list.count;

獲取值: object n = list["名"];

三。佇列:特點:先進先出

queues = new queue();

進隊:s.enqueue("我"); //進隊

出隊:sting str = s.dequeue();

不能插隊,不能中間離隊。

四、棧:特點:先進後出。

stacks = new stack();//棧

進棧:s.push("我");

出棧:string str = s.pop();

不能中間插入,不能中間離開。

函式:遞迴

列舉

其他語句2

1.switch if else if.switch 表示式 2.while for int i 0 變數初化。while 迴圈條件 do.while foreach 元素型別 變數 in 集合或陣列 3.鋸齒陣列 陣列的陣列 定義 a.定義陣列的陣列 int a new int 3 b.定義一維陣...

其他型別轉數字型別

number 數字型別的字串,轉換之後得到的數字。var n1 1 console.log number n1 1 非數字字串,轉換之後得到是nan var n3 123abc console.log number n3 nan var n4 yz99 console.log number n4 n...

其他資料型別

資料型別 作用 sql variant 用於儲存各種資料型別 timestamp 用於反應資料庫中資料修改的相對順序 uniqueidentifier 用於儲存乙個16位元組長的二進位制資料 xml 用於儲存整個xml文件 table 用於儲存對錶或者檢視查詢的結果集 cursor 用於對記者進行逐...