C#_Linq__集合操作

上传人:微*** 文档编号:171642586 上传时间:2022-11-28 格式:DOCX 页数:84 大小:278.80KB
收藏 版权申诉 举报 下载
C#_Linq__集合操作_第1页
第1页 / 共84页
C#_Linq__集合操作_第2页
第2页 / 共84页
C#_Linq__集合操作_第3页
第3页 / 共84页
资源描述:

《C#_Linq__集合操作》由会员分享,可在线阅读,更多相关《C#_Linq__集合操作(84页珍藏版)》请在装配图网上搜索。

1、Linq基础学习目录1 LINQ查询结果集12 System.Array 数组 I2.1 基于System.Array定义数组!2.2 基于类型定义数组12.3 数组元素的清空12.4 System.Array 类静态成员 I2.5 不用循环填充数组12.6 数组类实例成员23 System.Collections 集合23.1 Array Li st 21.1 !实例成员21.2 2静态成员21.3 List31.4 Hashtable 61.5 SortedList 61.6 SortedList71.7 Queue81.8 Stack81.9 LinkedList81.10 HashSe

2、t94 Sy stem. Linq 104.1 System.Linq.Queryable 104.2 System.Linq.Lookup 104.3 System.Linq.Expressions.Expression 105 接口105.1 lEnumerable IEnumerator 105.1.1 正常使用105.1.2 C#的 yield 125.2 lEnumerable 125.3 lEnumerator 125.4 ICollection 125.5 ICollection 135.6 IList 135.7 IList 135.8 lEqualityComparer 13

3、5.9 lEqualityComparer 135.10 IDictionary 135.11 IDictionary 135.12 IDictionaryEnumerator 135.13 IComparer 135.13.1 接口方法说明 int Compare(object x, object y)135.13.2 ArrayList.Sort (IComparer)方法135.14 IComparer 145.14.1 接口方法 override int Compare(T x, T y)说明145.14.2 List.Sort (IComparer)方法145.15 System.L

4、inq.IGrouping145.17 System.Linq.IOrderedEnumerable145.18 System.Linq.IOrderedQueryable 145.19 System.Linq.IOrderedQueryable155.20 System.Linq.IQueryable 155.21 System.Linq.IQueryable155.22 System.Linq.IQueryProvider 156集合扩展方法)56.1 集合扩展方法的实现:个Where的例子156.2 延迟类!56.2.1 Select 选择!66.2.2 SelectMany 选择!66

5、.2.3 Where 条件166.2.4 OrderBy 排序升176.2.5 OrderByDescending 排序降176.2.6 GroupBy 分组176.2.7 Join联合查询186.2.8 GroupJoin 186.2.9 Take获取集合的前n个元素196.2.10 Skip跳过集合的前n个元素!96.2.11 Distinct过滤集合中的相同项196.2.12 Union连接不同集合,自动过滤相同项196.2.13 Concat连接不同集合,不会自动过滤相同项196.2.14 Intersect获取不同集合的相同项(交集)206.2.15 Except从某集合中删除其与另

6、个集合中相同的项206.2.16 Reverse 反转集合206.2.18 SkipWhile条件第一次不成立就失效,将后面的数据全取206.2.19 Cast将集合转换为强类型集合216.2.20 OfType过滤集合中的指定类型216.3不延迟(浅复本)216.3.1 Single集合中符合条件的唯一元素,浅复本216.3.2 SingleOrDefault集合中符合条件的唯一元素(没有则返回类型默认值),浅复本216.3.3 First集合的第一个元素,浅复本216.3.4 FirstOrDefault集合中的第一个元素(没有则返回类型默认值),浅复本226.3.5 Last集合中的最后

7、一个元素,浅复本226.3.6 LastOrDefault集合中的最后个元素(没有则返回类型默认值),浅复本226.3.7 ElementAt集合中指定索引的元素,浅友本226.3.8 ElementAtOrDefault集合中指定索引的元素(没有则返回类型默认值),浅复本226.3.9 Contains判断集合中是否包含有某一元素226.3.10 Any判断集合中是否有元素满足某一条件226.3.11 All判断集合中是否所有元素都满足某一条件236.3.12 SequenceEqual判断两个集合内容是否相同236.3.13 Count , LongCount集合中的元素个数236.3.1

8、4 AverageSum集合平均值求和236.3.15 Max、Min集合最大值,最小值246.3.16 Aggregate根据输入的表达式获取一个聚合值246.3.17 DefaultlfEmpty查询结果为空则返回默认值,浅复本246.3.18 ToArray将集合转换为数组,浅复本246.3.19 ToList将集合转换为ListT集合,浅复本256.3.20 ToDictionary将集合转换为K, V集合,浅复本257 Lambda表达式257.2 例2(多参)277.3 例3(list.Where)277.4 Lambda 表达式中 Lifting 288 QuerySyntax

9、査询语法298.2 from in select 308.3 orderby 排序308.4 group by into 分组318.5 join in on equals 联合查询338.6 into 汇总339 DataSource 数据绑定34LINQ查询结果集LinqSystem. Collections. Generic. IEnumerableLinq to DataSetSystem. Data. Enumcrab 1eRowCollectionLinq to SQLSystem. Linq. IQueryableLinq to XMLSystem. Collections. G

10、eneric. IEnumerableSystem.Array 数组所有数组都继承于System.Array,数组可以用System.Array建立数组可以是维也可以是多维数组。维数”对应于用来识别每个数组元素的下标个数。维数可以多达32维。数组的每维都有一个非零的长度。在数组的每维中,数组元素按下标0到该维最高下标值连续排列.数组没有固定大小。数组在创建以后仍可以改变大小。数组是对象,因此每种数组类型都是个单独的引用类型。这意味着:1 .数组变量中含有指向数据的指针,这些数据包含元素、秩和长度信息。2 .在将一个数组变量赋值给另个数组变量时,只有指针进行了复制。3 .两个数组变量只有在具有相

11、同的维数和元素数据类型时,才能看成是同一数据类型的数组变量。基于System.Array定义数组System. Array x=System. Array. Createlnstance(typeof(string),7);x. SetValue(*4*,0);y. SetValue(*8*,1);z. SetValue(*7*,2);aa. SetVaIue(*l*,3);bb. SetValue(*3*,4);cc. SetValue(*2*5);dd. SetValue(*5*,6);System. Console. WriteLine(x. GetValue(5);使用这种方式声明,只

12、能用SetValue与GetValue方法进行赋值与取值,不能使用xi的方式,也不会有xi.方法。出现基于类型定义数组类型,数组名=new类型该维个数,该维个数;类型,数组名;数组名=new类型个数,个数;类型,数组名;数组名=new类型L值1,值2,值3,值1,值2,值3;类型,数组名=值1,值2,值3,值1,值2,值3;类型口数组名=值1,值2,值3;数组元素的清空数组名=null;这时不只数组中的元素数据被清空了,而且数组的元素也被清空了.如果要再使用该数组,需要用重新指定维中的元素个数.数组的维结构不能被清除.System. Array类静态成员清空指定数组位置中元素的值Array.C

13、lear(数组名,从第几个开始,清除几个)把源数组名中的数据复制到冃标数组名Array.Copy(源数组名,目标数组名,要复制的个数)按升序排列.只能对维数组使用Array.Sort(数组名)对数组中的元素的顺序返转.Array. Reverse(数组名)从前向后在数组中查找指定的值.反回在数组中的位置值,如果没找到返回1,第一个位置是0.Array.lndexOf (数组名,要找的内容,开始位置)从后向前在数组中查找指定的值.反回在数组中的位置值,如果没找到返回1,第一个位置是0.i = Array.LastlndexOf (数组名,要找的内容,开始位置)不用循环填充数组stringf v

14、= new string50;v0=*wxwinter*;System. Collections. ArrayList. Repeat(v0, v. Length). CopyTo(v);泛型方法见集合的实例泛型方法数组类实例成员属性Rank返回数组的维数属性Length返回数组中元素的个数.方法GetLength(维数)返回指定维数中元素的个数.第维是扩展方法见集合扩展方法System.Collections 集合ArrayListSystem.Collections个数组型集合,使用的是随顺存储实例成员Capacity 属性获取或设置ArrayList可包含的元素数.当实际元素超过Capa

15、city属性时,Capacity属性会在原来的数值上翻倍Count属性集合中元素的个数int = Add(object)将对象添加到集合尾部AddRange (Array/List)将(Collection的元素添加到ArrayList的末尾object = Clone()创建ArrayList的浅表副本ArrayList =GetRange(index, count)源ArrayList中元素的子集.可以看成一个视图,两个集合数据是同步的lnsert(i,object)将对象插入到集合的指定位置InsertRange(index, Array/List)将 Collection的元素插入到A

16、rrayList的指定索引处Remove(object)从集合中移除指定对象RemoveAt(index)从集合中移除指定位置处的对象RemoveRange(index,count)从ArrayList中移除一定范围的元素SetRange(index,Array/List)将参数中的集合覆盖到调用该方法的集合的指定位置Reverse()返转集合中的对象Sort()对集合排序対象集合见 System.IComparable 接口Sort (IComparer)方法见 System.Collections.(Comparer 接口Clear()清除集合中所有元素向后查找lnteger=集合名nde

17、xOf (要找的内容变量,开始找的位置)从前向后在数组中查找指定的值.反回在数组中的位置值,如果没找到返回-1,第一个位置是.向前査找Integer =集合名.LastndexOf(要找的内容变量,开始位置)从后向前在数组中查找.反回在数组中的位置值,如果没找到返回1访问集合中的成员集合index静态成员ArrayList Is2= ArrayList.FixedSize(ls1)Is2的元素允许修改,但不允许添加或移除。两个集合数据是同步的ArrayList Is2= ArrayList. ReadOnly(ls1)IS2的元素只读。两个集合数据是同步的ListSystem.Collecti

18、ons.GenericSystem. Collections. Generic. List jh = new List();jh. Add (new TextBox 0);jh. Add (new TextBox ();jh. Add (new TextBox ();int i =100;foreach (System. Windows. Forms. TextBox tp in jh)(i = i +100;tp. Text =i. ToStringO ;tp. Left = i;this. Controls. Add(tp);class apublic a(string v) s = v;

19、public string s;使用System. Col lections. Generic. Li st jh = new Lista();jh.Add(new a(*123*);jh. Add (new a (*456*);jh. Add (new a (*789*);foreach (a tp in jh)(System. Console. WriteLine(tp. s);)除ArrayList方法外ConvertAIIpublic List ConvertAll(Converter converter)创建复本调用委托System. Converterpublic delegate

20、 TOutput ConverterTInput, TOutputXTInput input);将对象从一种类型转换为另一种类型的方法1.将当前List中的元素转换为另种类型,并返回包含转换后的元素的列表public static void MainO标准委托(List Is = new List()*1*,*2*,*3*);/System. Converter cw=new Converter(stringToint);/List li = Is. ConvertAll(cw);List li= Is. ConvertAlKint(stringToint);public static int

21、 stringToint(string s)(return int. Parse(s);)匿名方法List Is = new List()1,*2*,“3;List1 i = Is. ConvertAll(delegate(string s) return int. Parse(s););Lambda表达式List Is = new List() T,*2*,*3*);List li = Is. ConvertAlKint(i=int. Parse(i);集合扩展方法List Is = new List()*1*,2,3;/ System. Collections. Generic. IEnu

22、merable li = Is.Select(i = int. Parse(i);var li = Is. Select(i=int. Parse(i);1.将当前List屮的元素值批量修改static void Main(stringLJ args)(List Is = new List()1,2,3;List li = Is. ConvertAlKstring (stringAdd);public static string stringAdd(string s)return s+“wxd;ForEachpublic void ForEach ( Action action)对List的每

23、个元素执行指定操作调用委托System. Act ion public delegate void Action(T obj)对传递给它的对象执行某个操作的方法的委托标准委托static void Main(string args)List Is = new Liststring“wxd ,Izm;/ System. Action w = new System. Action(wxdPrint);/ Is. ForEach(w);Is. ForEach(wxdPrint);)static void wxdPrint(string s)(Console. WriteLine(s);)匿名方法Li

24、ststringIs = new Liststring“wxd,Izm;Is. ForEach(delegate(string name) Console. WriteLine(name););Lambda表达式List Is = new List wxd*,*Izm1;Is. ForEach(v= Console. WriteLine(v);集合扩展方法Find、FindLast、Findlndex FindLastlndex、Exists、TrueForAIIpublic T Find (Predicate match)检索与条件匹配的所有元素,并返回整个List中的第一个匹配元素,其中包

25、含与指定谓词所定义的条件相匹配的所有元素;否则为个空List创建复本FindLast 返回索引值 public T FindLast ( Predicate match)Findindex 返回索引值 public int Findindex ( Predicate match)FindLastIndex 返回逻辑型 public int FindLastIndex ( Predicate match)Exists 返回逻辑型 public bool Exists ( Predicate match)TrueForAI!返回逻辑型,确定是否List中的每个元素都与指定的谓词所定义的条件相匹配p

26、ublic bool TrueForAII ( Predicate match)调用委托System. Predicatepublic delegate bool Predicate(T obj);定义一组条件并确定指定对象是否符合这些条件的方法public static void MainOr标准委托List Is = new List()/System. Predicateint cw = new / int a = Is. Find(cw);int a = Is. Find(wxdFind);1,2,3;Predicate(wxdFind);)public static bool wxd

27、Find(int v)(bool b =(v =2);/Z 查找条件 return b;)匿名方法Listint Is = new List()1,2,3;int a = Is. Find(delegate(int v)1 bool b =(v =2); return b;);Lambda表达式List Is = new List()1,2,3;int a = Is. Find(v = v =2);FindAIIpublic List FindAII (Predicate match)检索与条件匹配的所有元素,如果找到,则为个List,其中包含与指定谓词所定义的条件相匹配的所有元素;否则为个空

28、List创建复本调用委托System. Predicatepublic delegate bool Predicate(T obj);定义组条件并确定指定对象是否符合这些条件的方法标准委托public static void MainO(List Is = new List()1,2,3;/ System. Predicate cw = new Predicateinl(WxdFind);/List li = Is. FindAll(cw);List1i = Is. FindAl1(WxdFind);)public static bool WxdFind(int v)(bool b =(v =

29、2);/Z 查找条件return b;)匿名方法List Is = new List()1,2,3;List1i = Is. FindAl1(delegate(int v) bool b =(v =2);return b;);Lambda表达式List Is = new List()1,2,3);List li = Is.FindAll(v = v =2);集合扩展方法以视图形式,不创建复本List Is = new List()1,2,3,4,5);/System. Collections. Generic. IEnumerable li = Is. Where(i = i i 3);Rem

30、oveAIIpublic int RemoveAII (Predicate match)移除与指定条件相匹配的所有元素。调用委托System. Predicatepublic delegate bool PredicateT(T obj);定义一组条件并确定指定对象是否符合这些条件的方法标准委托static void Main(string args)(List Is = new List()1,2,2,3,4,5;/System. Predicate cw = new Predicateint(WxdRem);/int n = Is. RemoveAll(cw);int n = Is. Re

31、moveAl 1(WxdRem);/n 为移除的个数public static bool WxdRem(int v)(bool b =(v =2);/Z 条件return b;)匿名方法List Is = new List()1,2,2,3,4,5);int n = Is. RemoveAll(delegate(int v) bool b =(v =2);return b;);Lambda表达式List Is = new List()1,2,3;Is. RemoveAll(v = v=2);Sortpublic void Sort ( Coinparison comparison)对List或

32、它的一部分中的元素进行排序Sort ()方法见 System.Comparable接口、System.lComparablevT接口Sort (Comparer)方法见 System.Collections.(Comparer 接口、System.Collections.Generic.IComparer接口调用委托System. Comparison public delegate int Comparison(T x, T y)表示比较同一类型的两个对象的方法x小于y返回小于的负数x等于y返回x大于y返回大于的正数标准委托static void Main(string args)(List

33、int Is = new List1,3,2,4,5,0,8,1;/ System. Comparison w = new Comparison(wxdSort);/ Is. Sort(w);Is. Sort(wxdSort);)static int wxdSort(int x, int y)(int v = x - y;return v;/return -v;升序)匿名方法List Is = new List1,3,2,4,5,0,8,11:Is. Sort(delegate(int x, int y) return x - y;);Lambda表达式List Is = new List1,

34、3,2,4,5,0,8,1;Is. Sort (x, y)= y - x);集合扩展方法以视图形式,不创建复本不改变原集合的顺序List Is = new List()1,3,2,4,5,0,8,1;/System. Collections. Generic. IEnumerable1i = Is. OrderBy(i = i);var li = Is. OrderBy(i = i);HashtableSystem.CollectionsSystem.Collections.DictionaryEntry 结构字典键/值对散列表(也叫哈希表),是根据关键码值直接进行访问的数据结构,也就是说,它

35、通过把关键码值映射到表中一个位置来访问记录,以加快查找的速度。这个映射函数叫做散列函数,存放记录的数组叫做散列表。哈希表使用的是链式存储哈希表使用键值对的方式来存储哈希表中,键名不能重复添加键对实例.Add(键,值);查找值bool =实例.ContainsValue(值)查找键bool =实例.ContainsKey(键)移除键对实例.Remove(键)清空集合实例.Clear。通过键访问值X键得到所有键集合foreach(object tl in x.Keys)(System. Console. WriteLine(tl);得到所有值集合foreach(object t2 in x. Va

36、lues)System. Console. WriteLine(t2);得到所有键值对集合foreach (object zd in x)(System. Collections. DictionaryEntry obj =(DietionaryEntry)zd;System. Console. WriteLine(obj. Key);System. Console. WriteLine(obj. Value);!SortedListSystem.CollectionsSortedList 将 ArrayList 与 Hashtable 的功能集成集合容量实例.Capacity属性查找键boo

37、l =实例.ContainsKey(键)查找值bool =实例.ContainsValue(值)得到索引处值object =实例.GetBylndex(index)设置索引处值实例.SetBylndex(3,值)通过键访问值实例键移除键对实例.Remove(键)移除索引处键对实例.RemoveAt(index)得到所有值集合得到所有键值对集合得到所有键值对集合SortedListSystem.Collections.Generic/System. IComparable定义通用的比较方法,由值类型或类实现以创建类型特定的比较方法。class a : System. IComparable(pu

38、blic a(string va, int le)(s = va;1= le;public string s;public int 1;实现 System. IComparable. CompareTopublic int CompareTo(object obj)if (object. Equals(this, obj)(return 0;)else(return 1;/使用System. Col lections. Generic. SortedList jh=newSortedList();a kl = new a(*123*,0);a k2= new a(*456*,100);a k3

39、=new a(*789*,200);jh. Add(kl, new TextBox ();jh. Add (k2, new TextBox ();jh. Add(k3, new TextBox ();值操作foreach (TextBox tp in jh.Values)this. Controls. Add(tp);/键操作foreach (a tp in jh. Keys)(tp.s =ok*;)键值对操作foreach (System. Collections. Generic. KeyValuePair tp in jh) tp. Value. Text = tp. Key. s;tp

40、. Value. Left = tp. Key.1;通过键操作值jhk2. Text =hello;QueueSystem.Collections.Genericclass a(public a(string v)(S = V;)public string s;/使用System. Collections. Generic. Queue jh = new Queue();入队jh.Enqueue(new a(*a);jh.Enqueue(new a(b);jh.Enqueue(new a (c);出队:每执行次出个if (0!= jh. Count)a obj = jh.Dequeue 0;S

41、ystem. Console. WriteLine(obj. s);StackSystem.Collections.Genericclass a(public a (string v)js = v;public string s;)使用System. Col lections. Generic. Stack jh = new Stacka();入栈jh. Push(new a(a);jh. Push (new a(*b*);jh. Push (new a(*c*);出栈:每执行次出个if (0!= jh. Count)a obj = jh. Pop ();System. Console. Wr

42、iteLine(obj. s);LinkedListSystem.Collections.Genericclass a(public a(string v)s = v;public string s;)使用System. Collections. Generic. LinkedList lb = new LinkedLista();System. Col lections. Generic. LinkedListNode p;void添加结点()(p = new LinkedListNode(new a(*l*);lb.AddFirst(p);lb. AddAfter(lb. First, n

43、ew a(*2*);lb. AddBeforedb. First, new a(*3*);lb. AddLast (new a(4);lb. AddFirst(new a(*5*);void读取头尾结点。string fs = lb. First. Value, s;string Is = lb. Last. Value, s;System. Console. Wri teLine(fs +1s);)void 下节点(object sender, EventArgs e)(p = p. Next;if (p = null)System. Console. Wri teLine (到达边界”);

44、)else(System. Console. Wri teLine(p. Value, s);)void上结点()(p = p. Previous;if (p = null)System. Console. WriteLine(到达边界);elseSystem. Console. Wri teLine (p. Value, s);HashSetSystem.Collections.Generic提供高性能的集运算。集是组不重复出现且无特定顺序的元素System. Col lections. Generic. HashSet h = new HashSet();/h. Add(l);h.Add(

45、l);不报错h.Add(l);不报错h. Add (2);h. Add (2);不报错h. Add (3);只显示/I/2/3foreach (var v i n h)(System.LinqSystem.Linq.EnumerableSystem.Linq.QueryableSystem.Linq.Lookup System.Linq.Expressions.Expressionpublic delegate TR lzm(T vl);class Program (static void Main(string args)(System. Linq. Expressions. Express

46、ionlzm le 123;)接口 Enumerable I Enumerator枚举契Systen- Cobecti onx.lEnu mer itorpublic object Currentpublic void Reset。public bod McveNextO正常使用定义:public class 集合:System.Collections.CollectionBase, System.Collections.lEnumerable属性访问器成员 thisint index(get return (成员)Listindex;)添加成员public int Add(成员 v) ret

47、urn List.Add(v);实现 GetEnumerator 接口public new System.Collections.(Enumerator GetEnumerator()迭代器d = new迭代器(this);return d;)/以下为迭代器类迭代器子类public class 迭代器:System.Collections.lEnumeratorint index =-1;索引用集合jh;public迭代器(集合v)构造函数 jh = v;public void Reset。重新初始化索引index =-1;public object Current 返回当前索引所指的对象ge

48、treturn jh.Listindex;public bool MoveNext。将索引指针向下移动位 if (index jh.List.Count-1) index = index +1;return true;return false;/以下为成员类迭代器中的数据成员public class 成员 public string a;使用集合.成员s1= new集合.成员;集合.成员s2= new集合.成员;s1.a =*wxd;s2.a =Izm;集合j = new集合。;j.Add(sl);j.Add(s2);第种方法:显示使用System.Collections.(Enumerato

49、r ee = j.GetEnumerator。;while (ee.MoveNext。)集合.成员temp =(集合.成员)ee.Current;System.Console.WriteLine(temp.a );第二种方法:隐式使用foreach (集合.成员 bb in j)System.Console. WriteLine(bb.a);C#的 yield当编译器检测到迭代器时,它将自动生成lEnumerable或|Enumerable接口的CurrentsMoveNext 和 Dispose 方法省去了写 System.Collections.(Enumerator 的代码yield r

50、eturn expressionl;yield return expression2;yield return expressions;yield break;将终止迭代,后面的迭代将不输出yield return expression4;创建public class wxd : System.Collections.lEnumerable(string v = HaM, MbM, McH,d,e,f, MgM ;public System.Collections.(Enumerator GetEnumerator()for (int i =0; i v.Length; i+)yield re

51、turn vi;yield return ”wxd”;yield return “lzm”;使用wxd x = new wxd();第一种方法:显示使用System.Collections.lEnumerator ee = x.GetEnumerator();while (ee.MoveNext()string temp =(string)ee.Current;System.Console. WriteLine(temp);第二种方法:隐式使用foreach (string v in x)System.Console. WriteLine(v);结果abcgwxdIzm Enumerable

52、System.Collections.Generic公开枚举数,该枚举数支持在指定类型的集合上进行简单迭代。 Enumerator System.Collections.Generic支持在泛型集合上进行简单迭代。 CollectionSystem.CollectionsI Collection接口是System.Collections命名空间中类的基接口。I Collection 接口扩展圧 numerable; I Dictionary 和 IList 则是扩展 I Collection 的更为专用的接口。(Dictionary实现是键/值对的集合,如Hashtable类。IList实现是

53、值的集合,其成员可通过索引访问,如ArrayList类。某些集合(如Queue类和Stack类)限制对其元素的访问,它们直接实现Collection接口。如果| Dictionary接口和IList接口都不能满足所需集合的要求,则从| Collection接口派生新集合类以提高灵活性。 Collection System.Collections.Generic定义操作泛型集合的方法。IListSystem.CollectionsIList是!Collection接口的子代,并且是所有非泛型列表的基接口。IList实现有三种类别:只读、固定大小和可变大小。无法修改只读IList。固定大小的ILi

54、st不允许添加或移除元素,但允许修改现有元素。可变大小的IList允许添加、移除和修改元素。IList System.Collections.Generic表示可按照索引单独访问的组对象。I EqualityComparerSystem.Collections对象的相等比较IEqualityComparer System.Collections.Generic定义方法以支持对象的相等比较。 DictionarySystem.Collections键/值对基接口 Dictionary System.Collections.Generic表示键/值对的泛型集合。I DictionaryEnumer

55、atorSystem.Collections枚举字典的元素 ComparerSystem.Collections比较两个对象的方法接口方法说明 int Compare(object x, object y)int Compare(object xobject y)方法的返回值小于零:x小于y零:X等于y大于零:X大于ArrayList.Sort (IComparer)方法class Program(static void Main(string args)(ArrayList Is = new ArrayList () new wxd value =4, new wxd value =2, n

56、ew wxd value =1, new wxd value =3;Is. Sort (new wxd ();class wxd : System.Collections. IComparer public int value;public int Compare(object x, object y)(int v =(wxd)x). value -(wxd)y). value;return v;)IComparer System.Collections.Generic定义类型为比较两个对象而实现的方法。接口方法 override int Compare(T x, T y)说明override int Compare(T x, T y)方法的返回值小于零:X小于y零:x等于y大于零:x大于y。List-Sort (IComparer)方法class Programstatic void Main(strin

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!