untitled

Similar documents
untitled

untitled

untitled

untitled

untitled

untitled

I/O Files讀寫檔案:

untitled

九十三年第三期檔案管理工作研習營學員建議事項答覆情形彙整表

台灣經濟新報資料庫

Microsoft PowerPoint - ch5.pptx

了 立 連 立 量 領 來 例 蘭 便 不 數 不 論 更 更 更 力 更 參 例 來 例 見 量 度 量 量 參 論 量 行 量 量 瑩 理 來 錄 量 量 不 力 省 力 立 力 量 量 量 了 量 便 錄 錄 錄 料 說 省 6

臺灣地區的警察教育現況與展望

untitled

大陸黨報集團化發展之研究

1

untitled

微處理機實習期末專題

untitled

個人教室 / 網路硬碟

untitled

untitled

untitled

untitled

地方公共服務績效比較評量之探討—標竿學習策略的觀點

untitled

移民資料

人身保險業務員資格測驗方案

PowerPoint 簡報

untitled

untitled

untitled

中華人民共和國殘疾人保障法(2008年修訂)

untitled

4-04 論文封面(樣式)

untitled

untitled

untitled

untitled

untitled

國立陽明大學輻射防護計畫書

untitled

untitled

untitled

PowerPoint 簡報

untitled

untitled

第五章 實例個案

untitled

untitled

隱形眼鏡的世界

untitled

untitled

第五章 鄉鎮圖書館閱讀推廣活動之分析

untitled

untitled

嘉義市都市計畫保護區農業區土地使用審查要點(草案)

十四、特殊需求的嬰兒

四湖鄉志纂修

untitled

富春國小主題統整課程計畫表 每年級(教學群)至少三個主題

第一章 簡介

吃寒天真的能減肥嗎

untitled

untitled

untitled

第三章 我國非營業特種基金制度及運作現況

龍華科技大學

untitled

untitled

untitled

untitled

untitled

untitled

94年度學習障礙補救教學進階研習

untitled

untitled

untitled

untitled

untitled

untitled

untitled

untitled

untitled

untitled

untitled

untitled

朝 陽 科 技 大 學

untitled

中華民國第45屆中小學科學展覽會

untitled

經濟部標準檢驗局台南分局

untitled

untitled

untitled

行政院國科會九十一年度專題研究


國立自然科學博物館館訊第263期

untitled

untitled

Transcription:

1

Outline ArrayList 類 列類 串類 類 類 例 理

MSDN Library MSDN Library 量 例 參 列 [ 說 ] [] [ 索 ] [] 來 MSDN Library 了 類 類 利 F1 http://msdn.microsoft.com/library/ http://msdn.microsoft.com/library/cht/

Object object 參 類 都 object 參 object Boxing 參 boxing ex object o = (int) 1; UnBoxing UnBoxing ex int i = (int) o;

ArrayList 類 (1) 列 列 不 便 ArrayList 料量 列 行 度 列不 不

ArrayList 類 (2) System.Collections; Count 數 Add Insert Remove Clear Sort Reverse

例 sample5-a1 (1) ArrayList 列 ArrayList class car { public car(int x) { id = x; } public int id; }

例 sample5-a1 (2) static void Main(string[] args) { ArrayList myal = new ArrayList(); car mycar = new car(10); myal.add(12); myal.add("ives"); myal.add(mycar); Console.WriteLine("myAL[{0}] {1}",0,myAL[0]); Console.WriteLine("myAL[{0}] {1}",1,myAL[1]); Console.WriteLine("myAL[{0}] {1}",2,((car)myAL[2]).id); } ((car)myal[2]).id = 100; Console.WriteLine("myCar " + mycar.id);

練 sample5-b1 數 料 ( 不 數 ) 數 料 列 念 利 ArrayList 來 料 利 Sort 料 行

Outline ArrayList 類 列類 串類 類 類 例 理

列類 Rank 列 度 Length 列 數 GetLength 度 度 Clone 列 列 ( 不 參 參 ) Sort 列 IndexOf 參數 索

例 sample5-a2 (1) 列類 參 class car { public int id; }

例 sample5-a2 (2) static void Main(string[] args) { int[,] x = new int[2,3]; Console.WriteLine("Length " + x.length); Console.WriteLine("Rank " + x.rank); Console.WriteLine("GetLength(0) " + x.getlength(0)); Console.WriteLine("GetLength(1) " + x.getlength(1));

例 sample5-a2 (3) car[] mycar = new car[5]; for(int i=0; i<mycar.length; i++) { mycar[i] = new car(); mycar[i].id = i; } Console.WriteLine(); // 參 x[0,0] = 100; mycar[0].id = 100;

例 sample5-a2 (4) int[,] y = (int[,]) x.clone(); car[] mymoto = (car[]) mycar.clone(); y[0,0] = 0; mymoto[0].id = 0; Console.WriteLine("x[0,0] " + x[0,0]); Console.WriteLine("y[0,0] " + y[0,0]); Console.WriteLine("myCar[0].id " + mycar[0].id); Console.WriteLine("myMoto[0].id " + mymoto[0].id); }

練 sample5-b2 立 int 列 10 利 亂數來 (1~10) 數 (1~10) 列 列 數 若 列 數 列 列 列 來 念 利 IndexOf

Outline ArrayList 類 列類 串類 類 類 例 理

串類 Length 串 數 ( 度 ) ToUpper / ToLower 串 Insert 串 PadLeft / PadRight 度 IndexOf 串 Split 串 切 串 列 Replace 串 SubString 串

例 sample5-a3 串類 string str = "Alice is a good student!!"; Console.WriteLine(str); Console.WriteLine("ToUpper " + str.toupper()); Console.WriteLine("ToLower " + str.tolower()); Console.WriteLine("Insert " + str.insert(6,"wang ")) string[] strarray = str.split(' '); for(int i=0; i<strarray.length; i++) Console.WriteLine(strArray[i]);

練 sample5-b3 數 ( ) 列 數 念 利 Split 串 數

C c Console.WriteLine("{0:c}",4.5); //NT$4.50 數 Dn dn Console.WriteLine("{0:d5}",4); //00004 E e Console.WriteLine("{0:e}",4); //4.000000e+001 Fn fn Console.WriteLine("{0:f3}",4); //4.000 數 Nn nn Console.WriteLine("{0:n2}",4000); //4,000.00 六 X x Console.WriteLine("{0:x}",10); //a

數 串 0 數 數 數 料 0 數 # 數 數 數 料 數. 數 數 數 數 數 理, 數 1000 1000000 % 數 100

例 sample5-a4 (1) 數 串 double myvar1 = 0801234567; Console.WriteLine(" 1." + myvar1.tostring("(0##)###- ####")); int myvar2 = -12345; Console.WriteLine(" 2." + myvar2.tostring("######")); Console.WriteLine(" 3." + myvar2.tostring("000000"));

例 sample5-a4 (2) double myvar3 = -2.455; Console.WriteLine(" 4." + myvar3.tostring("#.##")); Console.WriteLine(" 5." + myvar3.tostring("00.00")); Console.WriteLine(" 6." + myvar3.tostring("00.00000")); double myvar4 = 1234567890; Console.WriteLine(" 7." + myvar4.tostring("#,#")); Console.WriteLine(" 8." + myvar4.tostring("#,")); Console.WriteLine(" 9." + myvar4.tostring("#,,")); Console.WriteLine("10." + myvar4.tostring("#,,,")); double myvar5 = 0.086; Console.WriteLine("11." + myvar5.tostring("#.#%"));

Outline ArrayList 類 列類 串類 類 類 例 理

類 DateTime ( 年 ) Math 數 數 數 見數 數 Random 亂數

例 sample5-a5 DateTime Math 類 Console.WriteLine(" " + DateTime.Now); Console.WriteLine("2 10 " + Math.Pow(2,10)); Console.WriteLine("-2 " + Math.Abs(-2)); Console.WriteLine("Sin(pi/2) " + Math.Sin(Math.PI/2));

練 sample5-b4 年 列 年 年 念 利 DateTime 年 來

Outline ArrayList 類 列類 串類 類 類 例 理

類 (1) 類 類 來 類 類 (.dll) 參 類 利 using 類

類 (2) 類 類 利 列 行 (.dll)

類 (3) 若 類 類 參

類 (4) 類

類 (5)

例 sample5-a6 (1) 類 立 類 數 類 ClassLibrary1 namespace ClassLibrary1 { public class myclass { public static int Add(int a, int b) { return a+b; } } }

例 sample5-a6 (2) sample5-a6 using System; using ClassLibrary1; namespace sample5_a6 { class Class1 { static void Main(string[] args) { Console.WriteLine("2+3=" + myclass.add(2,3)); Console.ReadLine(); } } }

練 sample5-b5 類 類 立 類 串 林 串 E-mail 類 E-mail 列 念 E-mail @ @. 利 string 類 IndexOf 來

Outline ArrayList 類 列類 串類 類 類 例 理

不 邏 邏 念 利 來 行 料 不 0 行 利 try catch 來

(1) 行 來 數 數 滑 滑

(2) 行 行行 行 數數 行 [ 行 ] 行 行 行 不 [ 不 ] 行 行 不 行

(3) 行 [] [] [ 數 ] [ 數 ] [ ] 來 數 數 行行 數 數 行 數 數

例 sample5-a7 數 x = 10; int c = 0; for(int i=0; i<10; i++) c+=i; c += x; ArrayList myal = new ArrayList(); myal.add(c); x = (int)myal[0];

Outline ArrayList 類 列類 串類 類 類 例 理

例 理 (1) 行 讀 try catch finally 來 行 try catch 便 行 catch 理 不 catch 都 行 finally

例 理 (2) 例 類 都 Exception 例 類 例 類 類 Exception DivideByZeroException IndexOutOfRangeException InvalidCastException OverflowException 說 行 數 0 索 列 說 Message 例

例 理 (3) try { ; } catch ( 例 類 數 ) { ; } catch ( 例 類 數 ) { ; } finally { ; }

例 理 (4) try { int x = 0; x = 3/x; } catch { Console.WriteLine("!!"); } finally { Console.WriteLine(""); }

例 sample5-a8 (1) 數 x 3 x try { Console.Write(" 數 "); int x = int.parse(console.readline()); Console.WriteLine("" + (3/x)); }

例 sample5-a8 (2) catch { Console.WriteLine("!!"); } finally { Console.WriteLine(""); }

練 sample5-b6 數 x x 串 列 念 例 理來 串

例 理 throw 來 throw 例 類 throw new 例 類 (); throw new Exception("error!!");

例 sample5-a9 (1) 例 static int getmonth() { Console.Write(""); int month = int.parse(console.readline()); } if(month > 12 month <= 0) throw new Exception(" 不!!"); else return month;

例 sample5-a9 (2) static void Main(string[] args) { try { Console.WriteLine("" + getmonth()); } } catch(exception e) { Console.WriteLine(e.Message); } finally { Console.ReadLine(); }