這篇文章給大家分享的是有關(guān)C#如何實(shí)現(xiàn)數(shù)組操作的內(nèi)容。小編覺得挺實(shí)用的,因此分享給大家做個(gè)參考,一起跟隨小編過來看看吧。
在黑山等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、成都網(wǎng)站設(shè)計(jì) 網(wǎng)站設(shè)計(jì)制作按需定制網(wǎng)站,公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),品牌網(wǎng)站設(shè)計(jì),營銷型網(wǎng)站建設(shè),外貿(mào)營銷網(wǎng)站建設(shè),黑山網(wǎng)站建設(shè)費(fèi)用合理。
數(shù)組是相同類型的對象的集合。數(shù)組具有相同數(shù)據(jù)類型的項(xiàng)的有序集合。要訪問數(shù)組中的某個(gè)項(xiàng),需要同時(shí)使用數(shù)組名稱及該項(xiàng)與數(shù)組起點(diǎn)之間的偏移量。由于數(shù)組幾乎可以為任意長度,因此可以使用數(shù)組存儲數(shù)千乃至數(shù)百萬個(gè)對象,但必須在創(chuàng)建數(shù)組時(shí)就確定其大小。數(shù)組中的每項(xiàng)都按索引進(jìn)行訪問,索引是一個(gè)數(shù)字,指示對象在數(shù)組中的存儲位置或槽。
按順序演示了以下功能:
◆動態(tài)創(chuàng)建數(shù)組
◆數(shù)組快速排序
◆反轉(zhuǎn)數(shù)組元素
◆動態(tài)改變數(shù)組大小
◆檢索數(shù)組中元素
◆復(fù)制數(shù)組中多個(gè)元素
namespace StringDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { System.Collections.ArrayList mystrlist = new System.Collections.ArrayList(); mystrlist.Add("aaaaaaaa"); mystrlist.Add("bbbbbbbb"); mystrlist.Add("cccccccc"); mystrlist.Add("dddddddd"); foreach (string str in mystrlist) { textBox1.Text += str + "\r\n"; } } private void button2_Click(object sender, EventArgs e) { String[] myArray = { "8", "one", "4", "0", "over", "the" }; foreach (string str in myArray) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; Array.Sort(myArray); foreach (string str in myArray) textBox1.Text += str + "\r\n"; } private void button3_Click(object sender, EventArgs e) { String[] myArray = { "8", "one", "4", "0", "over", "the" }; foreach (string str in myArray) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; Array.Reverse(myArray); foreach (string str in myArray) textBox1.Text += str + "\r\n"; } private void button4_Click(object sender, EventArgs e) { String[] myArray = { "one", "two", "three" }; foreach (string str in myArray) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; Array.Resize(ref myArray, 5); myArray[3] = "aaa"; myArray[4] = "bbb"; foreach (string str in myArray) textBox1.Text += str + "\r\n"; } private void button5_Click(object sender, EventArgs e) { string[] dinosaurs = { "Compsog0000nathus", "Amargasaurus", "Ovira0000ptor","Veloc0000iraptor", "Deinonychus","Dilop0000hosaurus","Gallimimus", "Triceratops"}; foreach (string str in dinosaurs) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; //要自己寫一個(gè)SubStringis0000的函數(shù),這是泛型編程 string[] subArray = Array.FindAll(dinosaurs,SubStringis0000); foreach (string str in subArray) textBox1.Text += str + "\r\n"; } private static bool SubStringis0000(string str) { if(str.Contains ("0000")) return true ; else return false ; } private void button6_Click(object sender, EventArgs e) { string[] dinosaurs = { "Compsog0000nathus", "Amargasaurus", "Ovira0000ptor","Veloc0000iraptor", "Deinonychus","Dilop0000hosaurus","Gallimimus", "Triceratops"}; foreach (string str in dinosaurs) textBox1.Text += str + "\r\n"; textBox1.Text += "\r\n"; string[] deststr = new string[2]; //Copy還有很多類型的參數(shù),比如數(shù)組復(fù)制等。 Array.Copy(dinosaurs, 2, deststr, 0, 2); foreach (string str in deststr) textBox1.Text += str + "\r\n"; } private void button7_Click(object sender, EventArgs e) { textBox1.Text = ""; } } }
感謝各位的閱讀!關(guān)于“C#如何實(shí)現(xiàn)數(shù)組操作”這篇文章就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,讓大家可以學(xué)到更多知識,如果覺得文章不錯,可以把它分享出去讓更多的人看到吧!
名稱欄目:C#如何實(shí)現(xiàn)數(shù)組操作
瀏覽路徑:http://jinyejixie.com/article34/iehjse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供自適應(yīng)網(wǎng)站、云服務(wù)器、標(biāo)簽優(yōu)化、全網(wǎng)營銷推廣、面包屑導(dǎo)航、電子商務(wù)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)