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 |
新闻热点
疑难解答