C#
//宣告: 型別[] 變數名稱 = { 陣列內容1, 陣列內容2, 陣列內容3, 陣列內容4 ... }; string[] LocalNameList = { "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V" }; //巡覽1 foreach foreach (string _event in LocalNameList) { textbox1.text = _event; } //巡覽2 for for (i = 0; i < LocalNameList.Length; i++) { textbox1.text = LocalNameList[i]; } //排序 使用Array.Sort ( , ) //範例: //依檔名排序 = _event.Name; //or //依檔案最後修改的日期時間 = _event.LastWriteTime.ToString() private FileInfo[] SortFiles(FileInfo[] files) { int array_length = files.Length; string[] sort_key = new string[array_length]; foreach (FileInfo _event in files) { sort_key[0] = _event.Name; //依檔名 //sort_key[0] = _event.LastWriteTime.ToString(); //依檔案最後修改的日期時間 } Array.Sort(sort_key, files); //由小到大排序 Array.Reverse(files); //反轉 由大到小排序 return files; } //陣列Function的宣告 //類型 型別[] 名稱(參數...) private FileInfo[] SortFiles(FileInfo[] files) { return files; }
VB
'宣告: Dim 變數名稱() As 型別 = { 陣列內容1, 陣列內容2, 陣列內容3, 陣列內容4 ... } Dim LocalNameList() As String = {"G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V"} '巡覽1 For Each For Each _event As String In LocalNameList textbox1.text = _event Next '巡覽2 For For i = 0 To LocalNameList.Length - 1 textbox1.text = LocalNameList(i) Next '排序 使用Array.Sort ( , ) '範例: '依檔名排序 = _event.Name; 'or '依檔案最後修改的日期時間 = _event.LastWriteTime.ToString() Private Function SortFiles(ByVal files As FileInfo()) As FileInfo() Dim array_length As Integer = files.GetUpperBound(0) Dim sort_key(array_length) As String For Each dir As FileInfo In files sort_key(0) = dir.Name '依檔名 'sort_key(0) = dir.LastWriteTime.ToString '依檔案最後修改的日期時間 Next Array.Sort(sort_key, files) '由小到大排序 Array.Reverse(files) '反轉 由大到小排序 Return files End Function '陣列Function的宣告 '類型 Function 名稱(參數...) As 型別() Private Function SortFiles(ByVal files As FileInfo()) As FileInfo() Return files End Function
文章標籤
全站熱搜
留言列表