C# Hashtable中存入数组、List
哈希表中存入数组示例代码:
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 hash1 = new Hashtable(); // 创建哈希表
Hashtable hash2 = new Hashtable(); // 创建哈希表 string kk = "test";
int[] data = { , , , , }; //数组
hash1.Add("key", data); //数组作为值存入哈希表,对应键为key
hash1.Add(kk, data); int[] num1 = (int[])hash1["key"]; //取出键为key的值
int[] num2 = (int[])hash1[kk]; int x = ((int[])hash1["key"])[];
Console.WriteLine("x = " + x); Console.WriteLine("数组1:");
foreach (int i in num1) //打印数组1
Console.Write(i + " ");
Console.WriteLine("\n数组2:");
foreach (int i in num2) //打印数组2
Console.Write(i + " ");
}
}
}
输入结果为:
x =
数组1: 数组2:
请按任意键继续. . .
存入List示例代码:
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks; namespace ConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
List<int> list = new List<int>();
list.Add();
list.Add();
list.Add();
Console.WriteLine("list :");
foreach (int a in list)
Console.Write(a + " "); Hashtable hash = new Hashtable();
hash.Add("", list); Console.WriteLine("\n从哈希表中取出list:");
List<int> re = (List<int>)hash[""];
foreach (int aPart in re)
Console.Write(aPart + " ");
}
}
}
运行结果:
list :
从哈希表中取出list:
代码简单,可以一下就看懂,类的话与之类似。
C# Hashtable中存入数组、List的更多相关文章
- 键盘录入6个int类型的数据存入数组arr中,将arr数组中的内容反转...
一.有一道很有意思的数组操作相关编程题,闲来无事用JS解决了一下,问题描述如下: (1) 键盘录入6个int类型的数据存入数组arr中: (2) 将arr数组中的内容反转: (3) 将反转后的数组角标 ...
- javascript中关于数组的一些鄙视题
一.判断一个数组中是否有相同的元素 /* * 判断数组中是否有相同的元素的代码 */ // 方案一 function isRepeat1(arrs) { if(arrs.length > 0) ...
- Oc中的数组
========================== 数组 ========================== 一.认识数组 oc中可以把NSObject对象的子类放到数组这个集合中,但是int.f ...
- c语言输入一行未知个数数字存入数组
一直有个疑问输入一行数字存入数组时若不知道数字的个数怎么办,最容易想到的办法就是接收字符然后转化为数字,但这样太过麻烦. 今天上网查了下,说可以用ungetc()函数将字符送回输入流,在这里总结归纳一 ...
- 字符串匹配KMP算法中Next[]数组和Nextval[]数组求法
数据结构课本上给了这么一段算法求nextval9[]数组 int get_nextval(SString T,int &nextval[ ]) { //求模式串T的next函数修正值并存入数组 ...
- Java中的数组与集合
此文转载自:http://student-lp.iteye.com/blog/2082362 在java编程的过程中,我们不能确定某一类型的对象到底会需要多少,为了解决这个问题,java提供了容纳对象 ...
- c#中的数组、ArrayList、List区别【转】
首先说明C#中的Array类:Array 类是 C# 中所有数组的基类,它是在 System 命名空间中定义.Array 类提供了各种用于数组的属性和方法.关于Array类的一些属性及方法详见博文:C ...
- c#中的数组、ArrayList、List区别
首先说明C#中的Array类:Array 类是 C# 中所有数组的基类,它是在 System 命名空间中定义.Array 类提供了各种用于数组的属性和方法.关于Array类的一些属性及方法详见博文:C ...
- Vue中遍历数组的新方法
1.foreach foreach循环对不能使用return来停止循环 search(keyword){ var newList = [] this.urls.forEach(item =>{ ...
随机推荐
- Windows如何打包Qt程序
很多Qt爱好者想发布自己的Qt软件,但却发现在其他没有安装Qt SDK的机器上无法运行,这就是本文想要说明的问题.现在网上大部分软件都要发布自己开发的应用程序,都会打包到exe文件中,待安装完exe文 ...
- iOS 自动布局总结
参考自以下文章: http://blog.csdn.net/ysy441088327/article/details/12558097 http://blog.csdn.net/zhouleizhao ...
- Apple-Watch开发
Apple Watch界面设计规范(4) - 通知 Apple Watch界面设计规范(3) - Glance Apple Watch界面设计规范(2) - 应用解析 Apple Watch界面设计规 ...
- Bash函数使用
#!/bin/bash function Fun_Name() { #function here echo "this is a function" } Fun_Name
- jsp带参转链接
1.jsp:forward page <jsp:forward page="show.jsp"> <jsp:param name="data" ...
- WebForm开发常用代码
1.获取服务器绝对路径: public static string GetMapPath(string strPath) { if (HttpContext.Current != null) { re ...
- JavaScript核心
JavaScript核心 arguments对象 Array对象 Boolean对象 Date对象 Error对象 Function对象 Global对象 Math对象 Number对象 Object ...
- Android端上传图片到后台,存储到数据库中 详细代码
首先点击头像弹出popwindow,点击相册,相机,调用手机自带的裁剪功能,然后异步任务类访问服务器,上传头像,保存到数据库中, 下面写出popwindow的代码 //设置popwindow publ ...
- 自定义图文混排视图MyImageTextView
http://blog.csdn.net/xujunfeng000/article/details/36399339?utm_source=tuicool&utm_medium=referra ...
- 在Iframe框架下如何跳转到登录界面
在Iframe框架下跳转到登录界面总会跳到子界面中,类似于下图 试用Respon.Redirect()不行, 用Js函数,但我跳转代码都是写在cs文件中的,用Respose.write(),js函数根 ...