首页 > 其他 > 详细

C# Hashtable中存入数组或类

时间:2014-07-16 21:08:55      阅读:335      评论:0      收藏:0      [点我收藏+]

示例代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Collections;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Hashtable hash = new Hashtable();   // 创建哈希表
            int[] data = { 1, 2, 3, 4, 5 }; //数组

            hash.Add("key", data);  //数组作为值存入哈希表,对应键为key

            int[] num = (int[])hash["key"]; //取出键为key的值

            foreach (int i in num)  //打印数组
                Console.WriteLine(i);

        }
    }
}

输入结果为:

1
2
3
4
5

  代码简单,可以一下就看懂,存入类的话与之类似。

C# Hashtable中存入数组或类,布布扣,bubuko.com

C# Hashtable中存入数组或类

原文:http://www.cnblogs.com/vitah/p/3836217.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!