C#基础课程之五集合(HashTable,Dictionary)

发布时间:2016-12-6 7:19:11编辑:www.fx114.net 分享查询网我要评论
本篇文章主要介绍了"C#基础课程之五集合(HashTable,Dictionary) ",主要涉及到C#基础课程之五集合(HashTable,Dictionary) 方面的内容,对于C#基础课程之五集合(HashTable,Dictionary) 感兴趣的同学可以参考一下。

HashTable例子:    
 #region HashTable    
            #region Add    
            Hashtable hashTable = new Hashtable();    
            Hashtable hashTableNews = new Hashtable();    
            string[] StringArray=new string[5];    
            hashTableNews.Add(1, StringArray);    
            hashTableNews.Add(1, 3);    
            hashTableNews.Add(1,4);    
            Console.WriteLine(hashTableNews.);    
            object[] Array = new object[10];    
            hashTable.Add(1, "第一");    
            hashTable.Add(2, "第二");    
            hashTable.Add(3, "第三");    
            hashTable.Add(4, "第四");    
            hashTable.Add(5, "第五");    
            hashTable.Add(6, "第六");    
            #endregion    
            #region Contains    
            bool ContainsResult = hashTable.Contains(2);//查找Key值    
            Console.WriteLine(ContainsResult);    
            bool ContainsKeysResult = hashTable.ContainsKey(7);//查找Key值    
            Console.WriteLine(ContainsKeysResult);    
            bool ContainsValueResult = hashTable.ContainsValue("第一");//查找Value值    
            Console.WriteLine(ContainsValueResult);    
            #endregion    
            int i = hashTable.Count;    
            Console.WriteLine(i);    
            foreach (DictionaryEntry dicEntry in hashTable)    
            {    
                Console.WriteLine(" " + dicEntry.Key + " " + dicEntry.Value);    
            }    
            foreach (var key in hashTable.Keys)    
            {    
                Console.WriteLine(" " + key + " " + hashTable[key]);    
            }    
            Hashtable hashTableNew = (Hashtable)hashTable.Clone();//浅表复制,只复制结构    
    
            hashTable.CopyTo(Array, 3);    
            foreach (var item in Array)    
            {    
                Console.WriteLine(" " + item);    
            }    
            DictionaryEntry[] Array1 = new DictionaryEntry[10];    
            hashTable.CopyTo(Array1, 3);    
            foreach (DictionaryEntry item1 in Array1)    
            {    
                Console.WriteLine(" " + item1.Key + " " + item1.Value);    
            }    
            #region Equals    
            Hashtable hashTable1 = new Hashtable();    
            hashTable1.Add(1, "第一");    
            hashTable1.Add(2, "第二");    
            hashTable1.Add(3, "第三");    
            hashTable1.Add(4, "第四");    
            hashTable1.Add(5, "第五");    
            hashTable1.Add(7, "第六");    
            bool result1 = hashTable.Equals(hashTable1);    
            Hashtable hashTable2 = new Hashtable();    
            hashTable2.Add(1, "第一");    
            hashTable2.Add(2, "第二");    
            hashTable2.Add(3, "第三");    
            hashTable2.Add(4, "第四");    
            hashTable2.Add(5, "第五");    
            hashTable2.Add(6, "第六");    
            bool result2 = hashTable.Equals(hashTable2);    
            Console.WriteLine(result2);    
            Hashtable hashTable3 = hashTable;    
            bool result3 = hashTable.Equals(hashTable3);    
            Console.WriteLine(result3);    
            #endregion    
            Console.ReadLine();    
            hashTable.Remove(2);    
            hashTable.Clear();    
    
            #endregion    
            #region Dictionary    
           Dictionary<string, int> dictionary = new Dictionary<string, int>();    
           Dictionary<string, string[]> dictionary1 = new Dictionary<string, string[]>();    
           Dictionary<string, ArrayList> dictionary2 = new Dictionary<string, ArrayList>();    
           Dictionary<string, emp> dictionary3 = new Dictionary<string, emp>();    
           Dictionary<string[], int> dictionary4 = new Dictionary<string[], int>();    
           string[] value = new string[5];    
           value[1] = "10";    
           dictionary1.Add("1", value);    
           foreach (var item in dictionary1)    
           {    
               Console.WriteLine(" " + item.Key );    
               foreach (var items in item.Value)    
               {    
                   Console.WriteLine(" " + items);    
               }    
           }    
           Console.ReadLine();    
            #endregion    

 本系列教程:

C#基础总结之八面向对象知识点总结-继承与多态-接口-http://www.cnblogs.com/spring_wang/p/6113531.html

C#基础总结之七面向对象知识点总结1http://www.cnblogs.com/spring_wang/p/6113526.html

C#基础总结之六 DataTable (临时表/数据源) 和Datatable 名片练习http://www.cnblogs.com/spring_wang/p/6113520.html

C#基础总结之五Dictionary<string, string[]>和while循环http://www.cnblogs.com/spring_wang/p/6113514.html

C#基础总结之四List-Hashtable-冒泡排序http://www.cnblogs.com/spring_wang/p/6113504.html

C#基础总结之三循环控制-for-数组-乘法表-arraylisthttp://www.cnblogs.com/spring_wang/p/6113496.html

C#基础总结之二循环控制-运算符http://www.cnblogs.com/spring_wang/p/6113484.html

C#基础总结之一变量常量-if嵌套语句-witch结构-类型转换http://www.cnblogs.com/spring_wang/p/6113476.html

C#基础课程之六(临时表)DataTable使用方法http://www.cnblogs.com/spring_wang/p/6113454.html

C#基础课程之五集合(HashTable,Dictionary)http://www.cnblogs.com/spring_wang/p/6113404.html

C#基础课程之四集合(ArrayList、List<泛型>)http://www.cnblogs.com/spring_wang/p/6113396.html

C#基础课程之三循环语句http://www.cnblogs.com/spring_wang/p/6113383.html

C#基础课程之二变量常量及流程控制http://www.cnblogs.com/spring_wang/p/6113372.html

C#基础课程之一注释和控制台、一些常识http://www.cnblogs.com/spring_wang/p/6113361.html

C#基础第九天-作业答案-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113291.html

C#基础第九天-作业-储蓄账户(SavingAccount)和信用账户(CreditAccount) http://www.cnblogs.com/spring_wang/p/6113285.html

C#基础第八天-作业答案-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113274.html

C#基础第八天-作业-设计类-面向对象方式实现两个帐户之间转账http://www.cnblogs.com/spring_wang/p/6113258.html

C#基础第七天-作业答案-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113232.html

C#基础第七天-作业-利用面向对象的思想去实现名片-动态添加http://www.cnblogs.com/spring_wang/p/6113224.html

C#基础第六天-作业-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113028.html

C#基础第六天-作业答案-利用面向对象的思想去实现名片http://www.cnblogs.com/spring_wang/p/6113033.html

C#基础第五天-作业答案-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113022.html

C#基础第五天-作业-用DataTable制作名片集http://www.cnblogs.com/spring_wang/p/6113013.html

C#基础第四天-作业答案-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113005.html

C#基础第四天-作业-Hashtable-list<KeyValuePair>泛型实现名片http://www.cnblogs.com/spring_wang/p/6113000.html

C#基础第三天-作业答案-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112888.html

C#基础第三天-作业-集合-冒泡排序-模拟名片http://www.cnblogs.com/spring_wang/p/6112885.html

C#基础第二天-作业答案-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112881.html

C#基础第二天-作业-九九乘法表-打印星星http://www.cnblogs.com/spring_wang/p/6112875.html

C#基础第一天-作业答案http://www.cnblogs.com/spring_wang/p/6112872.html

C#基础第一天-作业http://www.cnblogs.com/spring_wang/p/6112867.html

C#-string.Format对C#字符串格式化http://www.cnblogs.com/spring_wang/p/6077098.html


上一篇:svn: Can't convert string from 'UTF-8' to native
下一篇:直通BAT面试算法精讲课1

相关文章

相关评论

本站评论功能暂时取消,后续此功能例行通知。

一、不得利用本站危害国家安全、泄露国家秘密,不得侵犯国家社会集体的和公民的合法权益,不得利用本站制作、复制和传播不法有害信息!

二、互相尊重,对自己的言论和行为负责。

好贷网好贷款