#region 获取Excel工作薄中Sheet页(工作表)名集合/// <summary> /// 获取Excel工作薄中Sheet页(工作表)名集合/// </summary> /// <param name="excelFile">Excel文件名称及路径,EG:C:\Users\JK\Desktop\导入測试.xls</param> /// <returns>Sheet页名称集合</returns> private String[] GetExcelSheetNames(string fileName){OleDbConnection objConn = null;System.Data.DataTable dt = null;try{string connString=string.Empty;s...
C# List集合类常用操作 (一)所有操作基于以下类 class Employees{public int Id { get; set; }public string Name { get; set; }public string City { get; set; }public DateTime BirthDate { get; set; }}
List()初始化 List 类的新实例,该实例为空并且具有默认初始容量。List<Employees> employees = new List<Employees>();
employees.Add(new Employees { Id = 1, Name = "Nancy.Davolio", City = "Seattle", BirthDate =...
一个集合可否排序,要看系统知不知道排序的规则,像内建的系统类型,int ,string,short,decimal这些,系统知道怎么排序,而如果一个集合里面放置的是自定义类型,比如自己定义了一个Car类型,要把它排序,系统是不知道怎么办的。那么,如何告知系统排序的规则呢?有以下几种方法:1:对类实现IComparable接口,示例如下:[csharp] view plain copy print?using System; using System.Collections.Generic; using System.Linq; ...
ArrayList alist = new ArrayList();//集合对像 长度可以改变,类型不限//添加单个元素可以Add()alist.Add("在在的");alist.Add(35);alist.Add(3.14);alist.Add(‘c‘);alist.Add(5000m);//如果用Add()添加数组或集合最好用 alist.AddRange()alist.AddRange(newint[] { 3, 43, 56, 7, 98, 7, 6, 5 });alist.AddRange(alist);// alist.Add(new int[] { 3, 43, 56, 7, 98, 7, 6, 5 });//会直接打印syste.int//if (alist[i] is int[...
看到这个标题,大家应该就知道有泛型集合,就有非泛型集合既然都是集合,咱们今儿就简单的来对比讲解下需要记住的不算太多,理解记忆、理解记忆 2017-11-0411:39:09C# 泛型集合之非泛型集合类与泛型集合类的对应:*****ArrayList对应List ***HashTable对应Dictionary*****Queue对应Queue*****Stack对应StackSortedList对应SortedList 第一 : ArrayList(非泛型集合) 与List(泛型集合)ArrayList 是数组的复杂版本。ArrayList...
1,Array ,ArrayList,List<类型> 数组, 连续分配的,查询速度快,但增删不方便 #region 链表2,LinkedList<类型>,LinkedListNode<类型> 链表 ,非连续分配,每个元素都有前后节点,找元素只能遍历,查找不方便,增删容易3,Queue<T> 队列,也是链表,先进先出,增删快,可以重复数据,一般放置任务,延迟执行4,Stack<T> 栈,也是链表,先进后出 1)Push 2)pok 3)#endregion #region Set:1,HashSet<T> hash集合...
List<string> list1=new List<string>();List<string> list2=new List<string>();//Tuple<List<string>, List<string>> tuple = new Tuple<List<string>, List<string>>(); //报错,不能这样初始化.Tuple<List<string>, List<string>> pfInfo = Tuple.Create(list1, list2); //创建一个新的二元 集合Tuple<List<string>, List<string>> pfs = pfInfo as Tuple<List<string>, List<string>>; //使用as语法 原文:https://www.cnblogs...
C#在foreach循环中修改字典等集合出错:System.InvalidOperationException: Collection was modified; enumeration operation may not execute.这是因为在foreach中不允许修改集合,可通过如下方式修改dictPublish的值,如:Dictionary<string, string> _dict = new Dictionary<string, string>(dictPublish); if ((_dict != null) && (_dict.Count != 0)){ foreach (KeyValuePair<string, string> item in _dict) { ...
集合框架是为表示和操作集合而规定的一种统一的标准的体系结构。任何集合框架都包含三大块内容:对外的接口、接口的实现和对集合运算的算法。java集合框架:1. 什么是框架:类库的集合2.集合框架:用来表示和操作的统一的架构,包含了实现集合的接口与类3.集合:存放数据的容器集合框架包含了两部分:一部分是接口,一部分是类4.为什么会出现接口:因为集合框架中的很多类 功能是相似的【所以用接口来规范类】主要结构图:简化图ol...
1staticvoid Main()2 {3var data = new ObservableCollection<string>();4 data.CollectionChanged += Data_CollectionChanged;5 data.Add("One");6 data.Add("Two");7 data.Insert(1, "Three");8 data.Remove("One");910 }
1112staticvoid Data_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
13 {
14 Console.WriteLine("...
1///<summary> 2/// 整数区间类3///</summary> 4privateclass Interval5 {6privateint _start = 0, _end = 0;7publicint Start8 {9get { return Math.Min(this._start, this._end); }10set { this._start = value; }11 }12publicint End13 {14get { return Math.Max(this._start, this._end); }15set { this._end = value; }16 }17publicbool Inside(int Value)18 ...
简单的方法就是使用Lambda表达式中的Count方法来实现,很多时候只需要一条语句。例如,有个实体集合List<Student> studentList表示全校学生的集合数据,我们需要查找出ClassCode即班级代码等于A101班的学生的人数。此时可使用下列Lambda表达式的语句来实现。int A101StudentCount=studentList.Count(t=>t.ClassCode="A101");在上述语句中t是lambda表示式的一种写法,代表list集合中的实体对象,你也可以写成a或者b。在上述的表达式...
在C#的List集合操作过程中,如果要获取List集合中的第一个元素对象,则一般会先通过获取到list[0]这种方式来获取第一个元素。其实在List集合中提供了获取最后一个元素的First()方法,调用此方法可直接获取List集合中第一个元素。例如有个List<int>集合的对象list1,需要获取到该集合对象的第一个元素可使用First()方法,具体如下: List<int> list1 = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; var firstInt=list1.F...
大多数集合都在System.Collections,System.Collections.Generic两个命名空间。其中System.Collections.Generic专门用于泛型集合。针对特定类型的集合类型位于System.Collections.Specialized;命名空间;线程安全的集合类位于System.Collections.Concurrent;命名空间。下面是集合和列表实现的接口如下: 一、列表 [Serializable][DebuggerTypeProxy(typeof(Mscorlib_CollectionDebugView<>))][DebuggerDisplay("Count = {Count}...
在C#的List集合操作中,有时候需要将List元素对象拷贝存放到对应的数组Array中,此时就可以使用到List集合的CopyTo方法来实现,CopyTo方法是List集合的扩展方法,共有3个重载方法签名,分别为void CopyTo(T[] array)、void CopyTo(T[] array, int arrayIndex)、void CopyTo(int index, T[] array, int arrayIndex, int count)等三种形式,此文重点介绍CopyTo的第一种方法签名形式void CopyTo(T[] array)。首先定义个用于测试的类Te...