C#集合

news/2024/6/30 10:51:03
//int[] arr1 = new int[2] {1,2};//int[,] arr2 = new int[2, 3] {//    {0,1,2 },//    {2,3,4 }//    };//Console.WriteLine(arr2[1,1]); 普通集合//ArrayList
      
//ArrayList alt = new ArrayList(); 不需要规定长度和类型不能改变健值
 
        //alt.Add("123");//alt.Add(123);//alt.Add(true);
        alt.Remove(123);清楚ArrayList中的某个元素 清除int型的123
//bool iscontain = alt.Contains("1");如果元素中包含字符串1 如果有显示true没有显示flase
       //Console.WriteLine(iscontain); 

//alt.Clear();清楚所有ArrayList中的所有元素/*alt.Insert(0, "abc")*/; 插入索引值0内添加字符串abc//Console.WriteLine(iscontain);//for(int i = 0; i < alt.Count; i++)//{// Console.WriteLine(alt[i].ToString() + " " + alt[i].GetType().ToString()); 获取类型//}//foreach (var x in alt) var万能类型 遇见啥类型变成啥类型//{// Console.WriteLine(x.ToString() + " " + x.GetType().ToString());x.GetType()获取x类型
 x.GetType().ToString()获取x的类型并转化成字符串型
//} 
//泛型集合


List
//List<string> str_list = new List<string>(); <中添加类型> 不规定长度但要规定类型 不能改变健值

//str_list.Add("a");

//str_list.Add("b");

//str_list.Add("c");

//str_list.Add("d");
//foreach(string x in str_list)

//{ // Console.WriteLine(x); //}

//哈希表hashtable 没有顺序概念

//Hashtable ht = new Hashtable();

//ht.Add("1","a"); 括号内第一个为健值(索引值) 第二个为添加的元素

//ht.Add(2, "b");

//ht.Add(3, false);

//ht.Add("x", 3.14);

//Console.WriteLine(ht[2]);取出哈希表中健值2所对应的内容
//foreach(var x in ht.Keys) 遍历健值 Values遍历元素
//{

// Console.WriteLine(ht[x]);

//}

//字典表 Dictionary

//Dictionary<string, int> dic = new Dictionary<string, int>();<健值类型,.类型>
//dic.Add("a", 3); 和上面的类型想对应
//dic.Add("b", 4);

//dic.Add("c", 5);

//dic.Add("d", 6);
//dic.Add("e", 7);

//foreach(var x in dic.Keys)


//{ // Console.WriteLine(x); //}
特殊集合

//队列 queue 那个先进去哪个先出来 一般放进程

//Queue que = new Queue();

//que.Enqueue("张三"); 添加元素Enqueue

//que.Enqueue("李四");

//que.Enqueue("王五");

//que.Enqueue("赵六");

//Console.WriteLine("现在的长度是" + que.Count); 4
//Console.WriteLine(que.Dequeue()); 移除张三 Dequeue是移除的意思

//Console.WriteLine("现在的长度是" + que.Count); 3


//堆栈 stack 那个后进去那个先出来
Stack st
= new Stack();
st.Push(
"a");
st.Push(
"b"); push添加
st.Push(
"c");
st.Push(
"d");
Console.WriteLine(st.Count);
Console.WriteLine(st.Pop()); 移除
Console.WriteLine(st.Count);

 

转载于:https://www.cnblogs.com/skyhorseyk/p/6993845.html


http://lihuaxi.xjx100.cn/news/240551.html

相关文章

[vijos1234]口袋的天空最小生成树

题目链接&#xff1a;https://vijos.org/p/1234 白天刚刚写完prim的算法&#xff0c;晚上就心血来潮的打了一道最小生成树的题 虽然有题解说可以用prim做&#xff0c;但是这道题明显是加最小的边&#xff0c;感觉kruskal方便多了 但是愉快的是我竟然不是一次过&#xff0c;最后…

2014年数字:我的人生在命令行中

by freeCodeCamp通过freeCodeCamp 2014年数字&#xff1a;我的人生在命令行中 (2014 in Numbers: My Life Behind the Command Line) For 2014, I decided to simplify my life. Rather than pursuing a variety of human experiences, as I had previously, I wanted to focu…

linux 将文件的特定行写入另一个文件

问题背景 &#xff1a;博主处理了数据集&#xff0c;一个文件是class namefocal method&#xff0c;另一个文件是test case 对 test case 进行过滤之后得到了idx文件&#xff0c;然后根据idx文件提取出了对应的class namefocal method 现在想验证一下对应序号的class namefoc…

Java读取Properties配置文件

目录1.Properties类与Properties配置文件2.Properties中的主要方法3.示例1.Properties类与Properties配置文件Properties类继承自Hashtable类并且实现了Map接口&#xff0c;使用键值对的形式来保存属性集。不过Properties的键和值都是字符串类型。2.Properties中的主要方法(1)l…

蚂蚁金服副总裁胡喜:金融科技进入2.0时代,拼的是基础技术升级

今日&#xff08;10月12日&#xff09;&#xff0c;在2017年云栖大会上&#xff0c;ATEC金融科技开放峰会在杭州云栖小镇召开。在会上的演讲中&#xff0c;蚂蚁金服副总裁、首席技术架构师胡喜表示&#xff0c;与金融科技1.0阶段提供更为高效的便捷的普惠能力相比&#xff0c;金…

javascript回调函数笔记

来源于&#xff1a;https://github.com/useaname/blog-study 在Javascript中&#xff0c;函数是第一类对象。意味函数可以像对象一样按照第一类被管理使用。回调函数是从一个叫函数式编程的编程范式中衍生出来的概念。简单来说&#xff0c;函数式编程就是使用函数作为变量。函数…

网页制作_网页

网页制作by Divya Mistry通过Divya Mistry 网页 (MePage) Web上的单页目标 (A Single-page Destination on the Web) After going through some front-end development tutorials on Free Code Camp, I decided to try my hands at this simple Zipline challenge of creating…

写了一个linux的计时脚本,能够输出时分秒

#!/bin/bashstart$(date %s)# 用需要计时的程序将下面这句替换掉 sleep 100;end$(date %s) take$(( end - start )) echo Time taken to execute commands is ${take} seconds.let min${take}/60 let left1${take}-$(( ${min} * 60 ))echo That is ${min} minutes and ${left1}…