[正文]数据类型-Hashtable和 List,Dictionary

            #region Hashtable和HashSet


            Hashtable ff = new Hashtable(); //创建哈希表
            ff.Add("33", "66");  //往哈希表里添加键值对
            ff.Contains("33");   //判断哈希表里是否包含该键
            ff.ContainsKey("33");
            ff.ContainsValue("33");
            string name = (string)ff["33"].ToString(); //取哈希表里指定键的值
            //ff.Remove("33"); //删除哈希表里指定键的键值对
            //ff.Clear();//移除哈希表里所有的键值对


            foreach (string item in ff.Keys)    //遍历所有的键
            {
                string str1 = (string)ff[item];
            }
            IDictionaryEnumerator en = ff.GetEnumerator();  //遍历哈希表所有的键,读出相应的值
            while (en.MoveNext())
            {
                string str1 = en.Value.ToString();
                string str2 = en.Key.ToString();
            }


            HashSet<string> cc = new HashSet<string>();
            cc.Add("11");
            cc.Add("22");
            cc.Add("33");
            cc.Add("44");
            string[] aestr = new string[6];
            cc.CopyTo(aestr);
            cc.GetEnumerator().MoveNext();//?


            #endregion


            #region List,Dictionary


            //List<string> listfx = new List<string>();//可
            List<string> listfx = new List<string>(aestr);
            listfx.Add("11");
            listfx.Add("11");
            listfx.Add("22");
            listfx.Add("33");
            listfx.Add("44");
            listfx.Add("55");
            listfx.Add("55");
            listfx.Add("66");


            //取值
            string listk1 = listfx[0];
            string listk2 = listfx.Find(x => { return x.Length > 1; });
            string listk3 = listfx.FindLast(x => { return x.Length > 1; });
            List<string> listk4 = new List<string>();
            listk4 = listfx.FindAll(x => 1 == 1);
            List<string> listk6 = listfx.GetRange(2, 4);
            string[] listk5 = listfx.ToArray();


            //迭代器
            foreach (var item in listfx)
            {
                string str1 = item;
                listfx.GetEnumerator().MoveNext();
                string str2 = item;
                listfx.GetEnumerator().MoveNext();
                string str3 = item;
                listfx.GetEnumerator().Dispose();
                string str4 = item;
            }


            //List<string>.Enumerator kkk3 = listfx.GetEnumerator();//?


            //判断元素是否全部符合条件 TrueForAll
            bool isbbb = listfx.TrueForAll(x =>
            {
                bool isff = false;
                if (!string.IsNullOrEmpty(x))
                {
                    isff = x.Length > 1;
                }
                return isff;
            });


            常用
            //listfx.AddRange();
            //listfx.Clear();
            //listfx.Contains();
            //CopyTo();
            //Exists();
            //FindIndex();
            //ForEach();
            //IndexOf();
            //InsertRange();
            //Remove();
            //RemoveAll();
            //RemoveAt();
            //RemoveRange();






            Dictionary<string, string> dicff = new Dictionary<string, string>();
            dicff.Add("k1", "1");
            dicff.Add("k2", "1");
            dicff.Add("k3", "2");
            dicff.Add("k4", "3");
            dicff.Add("k5", "4");




            #endregion
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值