新聞中心
在向大家詳細(xì)介紹VB使用ArrayList類之前,首先讓大家了解下.NET 基類的用法,然后全面介紹VB使用ArrayList類。

成都創(chuàng)新互聯(lián)公司是網(wǎng)站建設(shè)技術(shù)企業(yè),為成都企業(yè)提供專業(yè)的網(wǎng)站設(shè)計制作、網(wǎng)站設(shè)計,網(wǎng)站設(shè)計,網(wǎng)站制作,網(wǎng)站改版等技術(shù)服務(wù)。擁有十余年豐富建站經(jīng)驗(yàn)和眾多成功案例,為您定制適合企業(yè)的網(wǎng)站。十余年品質(zhì),值得信賴!
在對從輸入讀取的行進(jìn)行排序之前,程序需要將其存儲到一個數(shù)組中。我們將簡要討論可實(shí)現(xiàn)對象數(shù)組的 .NET 基類的用法。
修改源代碼
更改 C# 源文件 (class1.cs),如下面以斜體突出顯示的代碼所示。其他的差異(如類名)可忽略不計。
- // Import namespaces
- using System;
- // Declare namespace
- namespace MsdnAA
- {
- // Declare application class
- class QuickSortApp
- {
- // Application initialization
- static void Main (string[] szArgs)
- {
- // Describe program function
- Console.WriteLine ("QuickSort C#.NET Sample Application\n");
- // Prompt user for filenames
- Console.Write ("Source: ");
- string szSrcFile = Console.ReadLine ();
- Console.Write ("Output: ");
- string szDestFile = Console.ReadLine ();
- }
- }
- }
VB使用ArrayList類
我們將導(dǎo)入 System.Collections 命名空間,這樣我們就可以直接VB使用ArrayList類。此類實(shí)現(xiàn)大小可動態(tài)調(diào)整的對象數(shù)組。要插入新的元素,可以簡單地將對象傳遞到 ArrayList 類的 Add() 方法。新的數(shù)組元素將引用原始的對象,而垃圾回收器將處理它的釋放。
- string szElement = "insert-me";
- ArrayList szArray = new ArrayList ();
- szArray.Add (szElement);
要檢索現(xiàn)有的元素,請將所需元素的索引傳遞給 Item() 方法。另外,作為一種簡寫形式,還可以使用方括號 operator [],它實(shí)際上映射到 Item() 方法。
- Console.WriteLine (szArray[2]);
- Console.WriteLine (szArray.Item (2));
【編輯推薦】
- 全面展示VB.NET服務(wù)器端
- 淺談VB.NET數(shù)組聲明和初始化
- 描述VB.NET fnSimpleObjectToXML
- 討論VB.NET使用Sorted Lists
- 講解VB.NET COMBOBOX控件
當(dāng)前題目:兩步就可以掌握VB使用ArrayList類
轉(zhuǎn)載來源:http://m.fisionsoft.com.cn/article/dpcossh.html


咨詢
建站咨詢
