(200-06-14) VB.NET 教學 Collection

摘要:(200-06-14) VB.NET 教學 Collection

Collection(集合) [ 容器 ]

  1. 操作物件 動態參考其它物件
  2. mscorlib.dll(核心類別)   
  3. NAMESPACE:   (1)System.Collections
  4. NAMESPACE:   (2)System.Collections.Generic(泛型)
  5. 不限制數量(動態參考)
  6. 集合的觀念是於在參考 不在於值  (Aggregation 聚合)
  7. ArrayList 所存放是參考 不存放結構 如存放結構會用使AutoBoxing 包裝成Object

 


Imports System.Collections
Module TestArrayListCollection
    '主程式
    Public Sub Main()
        '定義區域變數 
        Dim names As ArrayList = New ArrayList()
        '參考物件
        names.Add("eric")
        names.Add(New Object())
        names.Add(100) 'AutoBoxing 包裝成Object
        names.Add("linda")
        '寫出去(使用Indexer 索引子語法
        System.Console.WriteLine(names(3)) ' names.ToString()

        ' 次數迴圈(IList順序性)
        For i As Int32 = 0 To names.Count - 1
            '問本尊
            If TypeOf names(i) Is String Then
                System.Console.WriteLine("字串:" + names(i))
            End If
            System.Console.WriteLine(names(i))
        Next

        '逐一參考(不Care 順序)
        For Each o As Object In names
            If (TypeOf o Is String) Then
                System.Console.WriteLine("字串:" + DirectCast(o,String))
            End If
        Next
    End Sub
End Module

Web Collection 實作

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (Control o in this.Panel1.Controls)
        {
            //判斷TextBox
            if (o is TextBox)
            {
                ((TextBox)o).ReadOnly = false;
            }
        }
    }
}

3-4章 課程投影片   課程投影片.rar