List<Book> thelib = Library.getbooks(); List<Book> found = thelib.FindAll(delegate(Book curbook) { if (curbook.isbn.StartsWith("...")) return true; return false; }); foreach (Book b in found) Console.WriteLine(b.isbn); |
public class MyVec<T> { public static MyVec<T> operator +(MyVec<T> a, T b) { a._list.Add(b); return a; } public override string ToString() { StringBuilder builder = new StringBuilder(); foreach (T a in _list) { builder.Append(a.ToString()); builder.Append(","); } string ret = builder.Remove(builder.Length - 1, 1).ToString(); return ret; } public MyVec<T<>findAll(Predicate<T> act) { MyVec<T:>t2 = new MyVec<T>(); foreach(T i in _list) { if (act(i)) t2._list.Add(i); } return t2; } // this is the inner object private List<T> _list = new List<T>(); } |
static void Main(string[] args) { MyVec<int> a = new MyVec<int>(); a += 12; a += 15; a += 32; MyVec<int> b = a.findAll(delegate(int x) { if (x < 20) return true; return false; } ); Console.WriteLine("vection original"); Console.WriteLine(a.ToString()); Console.WriteLine("vection found"); Console.WriteLine(b.ToString()); Console.ReadLine(); } |
vection original 12,15,32 vection found 32 |