摘要: 迭代器 能使你获得序列中所有元素而不用关心其类型是array,list,link list或者其他序列结构。 1,实现接口IEnumerable就可以实现数据迭代。其中调用GetEnumerator方法返回Enumerator接口的实现,就是迭代器本身。 class BookColletion:IEnumerable{ #region IEnumerable 成员 public IEnumerator GetEnumerator() { //return 一个IEnumerator对象 return ne... 阅读全文
posted @ 2013-12-31 15:27 UCanBeFree 阅读(176) 评论(0) 推荐(0)
摘要: //灵活使用别名使代码更加精简。 using ZClass2 = ZClass, string>; class XClass { //泛型方法 public static void MethodA(z param) { Console.Write(param.GetType().ToString()); } } class YClass { public T MethodA() { T t=default(T); return t; ... 阅读全文
posted @ 2013-12-31 09:09 UCanBeFree 阅读(203) 评论(0) 推荐(0)
摘要: using Temptest = Temptest; class Program { static void Main(string[] args) { Temptest x = new Temptest(); x.func(); //输出: //ConsoleApplication5.Temptest`1[System.String] Console.Read(); } } class Temptest { ... 阅读全文
posted @ 2013-12-31 09:07 UCanBeFree 阅读(220) 评论(0) 推荐(0)