国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C# 2.0 中關于泛型的用法實例

2024-07-21 02:29:56
字體:
來源:轉載
供稿:網友

1. 定義泛型類

using system;
using system.collections;
using system.collections.generic;
using system.text;

namespace windowsapplication1
{
    class blist<t>
    {
        arraylist arr = new arraylist();

        public t this[int i]
        {
            get
            {
                return (t)arr[i];
            }
            set
            {
               arr.add(value);
            }
        }

        public void add(t p_obj)
        {
            arr.add(p_obj);
        }

        public int count
        {
            get
            {
                return arr.count;
            }
        }

    }
}


2. 調用(放到任意的窗體事件中)
 private void button2_click(object sender, eventargs e)
        {

            blist<int> _list = new blist<int>(); // <int>里面可以替換任意已知類型
            for (int i = 0; i < 10; i++)
            {
                _list.add( i);
            }

            for (int i = 0; i < _list.count; i++)

                messagebox.show(_list[i].tostring());
        }

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 金坛市| 泾川县| 淮南市| 连江县| 天长市| 和林格尔县| 辛集市| 九寨沟县| 正定县| 大同市| 新河县| 措勤县| 西乌珠穆沁旗| 宁都县| 伊通| 桐庐县| 黔南| 专栏| 长乐市| 桑植县| 天峻县| 安庆市| 河南省| 伽师县| 威海市| 隆安县| 黄平县| 阿拉尔市| 会泽县| 丽水市| 天镇县| 四会市| 缙云县| 天祝| 房产| 博客| 玛纳斯县| 昆山市| 祁连县| 黑水县| 遂溪县|