• 11月18日随笔


    今天在云和学院复习了以前的知识,又学习了ArrayList和HashTable

    ArrayList实例:

    ArrayList arr = new ArrayList();
                int i = 123;
                string str = "宋连城";
                float f = 1.23f;
                decimal d = 2.13m;
                double dou = 22.16;
                arr.Add(i);
                arr.Add(str);
                arr.Add(f);
                arr.Add(d);
                arr.Add(dou);
                arr.Remove(dou);
                arr.RemoveAt(2);
                
                for (int j = 0; j < arr.Count; j++)
                {
                    Console.WriteLine(arr[j]);
                }
                Console.ReadKey();
    

     HashTable实例:

    Hashtable hash = new Hashtable();
                string id = "272012321029";
                string name = "宋丽";
                string id1 = "272012321028";
                string name1 = "婷婷";
                hash.Add(id,name);
                hash.Add(id1,name1);
                foreach (DictionaryEntry  item in hash)
                {
                    Console.WriteLine(item.Key);
                    Console.WriteLine(item.Value);
                }
                
                int[] array = {12,45,23,89 };
                foreach (var item in array)
                {
                    Console.WriteLine(item);
                }
                Console.ReadKey();
    

     foreach语法:

    foreach(集合中单个的类型 局部变量名 in 集合对象)
    {
    –// 循环体
    –// 循环体当中“局部变量”表示集合中遍历的数据
    }
    泛型集合
     List<int> list = new List<int>();
                for (int i = 1; i < 100; i++)
                {
                    list.Add(i);
                }
                foreach (var item in list)
                {
                    Console.WriteLine(item);
                }
                Console.ReadKey();
    

    Dictionary

    Dictionary <TKey,TValue>

    Dictionary实例:

     Dictionary<int, string> dic = new Dictionary<int, string>();
                dic.Add(1,"范冰冰");
                dic.Add(2,"周韦彤");
                dic.Add(3,"范玮琪");
                dic.Add(4,"蔡国庆");
                dic.Add(5, "孙俪");
                foreach (var item in dic)
                {
                    Console.WriteLine(item.Key);
                    Console.WriteLine(item.Value);
                }
                Console.ReadKey();
    
  • 相关阅读:
    xml转义字符在mybatis动态sql中的使用
    jdbc类型与java类型
    aop日志(记录方法调用日志)
    mysql数据库关联查询【lert join】常见使用
    maven项目基本配置
    mapper文件的参数传入与获取
    idea新建项目出现push rejected如何解决
    快速从2个List集合中找出相同/不同元素
    Windows 环境下安装RocketMQ
    RabbitMQ java客户端集成 Spring 开发环境
  • 原文地址:https://www.cnblogs.com/songfang/p/4106635.html
Copyright © 2020-2023  润新知