C#的ARRAYLIST 和HASHTABLE示例代码

本文通过示例展示了如何使用C#进行数组到集合的转换,并利用Add方法和Insert方法来添加元素。此外,还介绍了如何创建并读取Hashtable,以便存储键值对数据。

慢慢积累吧。

为了给公司升级服务器,等到现在。

IT不容易呀。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 using System.Collections;
 7 
 8 namespace ConsoleApplication3
 9 {
10     class Program
11     {
12         static void Main(string[] args)
13         {
14             int[] arr = new int[] { 1, 2, 3, 4, 5, 6 };
15             ArrayList List = new ArrayList(arr);
16             Console.WriteLine("Original collections: ");
17             foreach (int i in List)
18             {
19                 Console.Write(i + " ");
20             }
21             Console.WriteLine();
22             for (int i = 1; i < 5; i++)
23             {
24                 List.Add(i + arr.Length);
25             }
26             Console.WriteLine(" use add method add : ");
27             foreach (int i in List)
28             {
29                 Console.Write(i + " ");
30             }
31             Console.WriteLine();
32             List.Insert(6, 6);
33             Console.WriteLine("use insert method add: ");
34             foreach (int i in List)
35             {
36                 Console.Write(i + " ");
37             }
38             Console.WriteLine();
39             Console.WriteLine();
40             Console.WriteLine();
41             Hashtable hashtable = new Hashtable();
42             hashtable.Add("id ", "BH0001");
43             hashtable.Add("name ", "TM");
44             hashtable.Add("sex ", "Male");
45             hashtable.Add("age ", "25");
46             hashtable.Add("nation ", "China");
47             Console.WriteLine("\tkey\tvalue");
48             foreach (DictionaryEntry dicEntry in hashtable)
49             {
50                 Console.WriteLine("\t" + dicEntry.Key + "\t" + dicEntry.Value);
51             }
52 
53             Console.ReadKey();
54         }
55     }
56 }

转载于:https://www.cnblogs.com/aguncn/archive/2013/05/04/3058641.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值