【idior】.Net2.0的集合操作 --- What i know?
.Net2.0中提供的Array類
namespace System {
public abstract class Array {
public static TOutput[] ConvertAll<TInput, TOutput>(TInput[] input, Converter<TInput, TOutput> cc);
public static bool Exists<T>(T[] array, Predicate<T> match);
public static T Find<T>(T[] array, Predicate<T> match);
public static T FindLast<T>(T[] array, Predicate<T> match);
public static T[] FindAll<T>(T[] array, Predicate<T> match);
public static int FindIndex<T>(T[] array, Predicate<T> match);
public static int FindLastIndex<T>(T[] array, Predicate<T> match);
public static void ForEach<T>(T[] array, Action<T> action);
public static void Sort<T>(T[] array, Comparison<T> comparer);
public static bool TrueForAll<T>(T[] array, Predicate<T> match);
}
}
public abstract class Array {
public static TOutput[] ConvertAll<TInput, TOutput>(TInput[] input, Converter<TInput, TOutput> cc);
public static bool Exists<T>(T[] array, Predicate<T> match);
public static T Find<T>(T[] array, Predicate<T> match);
public static T FindLast<T>(T[] array, Predicate<T> match);
public static T[] FindAll<T>(T[] array, Predicate<T> match);
public static int FindIndex<T>(T[] array, Predicate<T> match);
public static int FindLastIndex<T>(T[] array, Predicate<T> match);
public static void ForEach<T>(T[] array, Action<T> action);
public static void Sort<T>(T[] array, Comparison<T> comparer);
public static bool TrueForAll<T>(T[] array, Predicate<T> match);
}
}
以上的集合操作使用到了下面的一些預先定義好的代理.(從他們的名字,你就可以明白他們是幹什麼的)
namespace System {
public delegate void Action<T>(T item);
public delegate int Comparer<T>(T first, T second); // result works like strcmp
public delegate TOutput Converter<TInput, TOutput>(TInput input);
public delegate bool Predicate<T>(T item);
}
public delegate void Action<T>(T item);
public delegate int Comparer<T>(T first, T second); // result works like strcmp
public delegate TOutput Converter<TInput, TOutput>(TInput input);
public delegate bool Predicate<T>(T item);
}
下面是一些例子
int[] list = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
int lastOdd = Array.FindLast(list, delegate(int n) { return n % 2 == 1; });
// lastOdd is 9
int[] evens = Array.FindAll(list, delegate(int n) { return n % 2 == 0; });
// evens contains { 2, 4, 6, 8, 10 }
bool hasMultipleOfSeven = Array.Exists(evens, delegate(int n) { return n % 7 == 0; });
// hasMultipleOfSeven is false
Array.Sort(evens, delegate(int a, int b) { return b - a; });
// evens is now { 10, 8, 6, 4, 2 } , you can define the sort algorithm by yourself
string[] s = Array.ConvertAll<int, string>(evens, delegate(int n) { return "#" + n.ToString(); });
// s is { "#10", "#8", "#6", "#4", "#2" } this will be cool if the compiler could do the inferencing for ConvertAll
int lastOdd = Array.FindLast(list, delegate(int n) { return n % 2 == 1; });
// lastOdd is 9
int[] evens = Array.FindAll(list, delegate(int n) { return n % 2 == 0; });
// evens contains { 2, 4, 6, 8, 10 }
bool hasMultipleOfSeven = Array.Exists(evens, delegate(int n) { return n % 7 == 0; });
// hasMultipleOfSeven is false
Array.Sort(evens, delegate(int a, int b) { return b - a; });
// evens is now { 10, 8, 6, 4, 2 } , you can define the sort algorithm by yourself
string[] s = Array.ConvertAll<int, string>(evens, delegate(int n) { return "#" + n.ToString(); });
// s is { "#10", "#8", "#6", "#4", "#2" } this will be cool if the compiler could do the inferencing for ConvertAll
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/12639172/viewspace-349331/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- 【idior】.Net2.0的集合操作 --- What i hope?
- What you should know about JavaJava
- I don’t know what to say 事件的 NPM 包中獎名單,有你在用的嗎?事件NPM
- PostgreSQL DBA(44) - Privileges & User Management - What You Should KnowSQL
- PostgreSQL DBA(71) - Locks(Table-Level):What You Should KnowSQL
- PostgreSQL DBA(74) - Locks(Row-Level):What You Should KnowSQL
- PostgreSQL DBA(75) - Locks(locktype:transactionid):What You Should KnowSQL
- PostgreSQL DBA(76) - Locks(Advisory Locks):What You Should KnowSQL
- what-i-learned-from-analysis-vuepressVue
- 2008 5 5: I want to get know you better
- 04 - Mongdb的集合操作
- Oracle 集合操作Oracle
- Scala 中的集合(一):集合型別與操作型別
- Hadoop的I/O操作Hadoop
- Redis有序集合操作Redis
- Linq 集合操作
- go操作redis的有序集合(zset)GoRedis
- Oracle的集合操作(union、union all、intersect、minus集合函式)Oracle函式
- What is the difference betn i step=2 and i step=3 in variable user exit EXIT SAPLRRS0 001
- What are HANA's models of cloud computing, and which should I choose?Cloud
- MySQL 命令列操作集合MySql命令列
- MongoDB 集合的插入、更新、刪除操作MongoDB
- javascript操作Select中的options集合JavaScript
- 2008.1.15 He didn't know it until I put a bug in his ear.
- 對.NET2.0泛型初步理解泛型
- GoldenGate - What is supported and what is not ....Go
- 02. I/O 操作
- 想入門者請近.[翻譯]what programming language should I learn?
- php操作redis,有序集合zsetPHPRedis
- Python集合操作總結Python
- Dart 集合操作外掛 DartXDart
- C#操作XML方法集合C#XML
- Linux 日常操作命令集合 -1程式操作Linux
- What is it?
- I/O流以及檔案的基本操作
- 流?I/O 操作?阻塞?epoll?
- Python&Redis 無序集合set、有序集合zset操作PythonRedis
- You don't know CSSCSS