C# 学习笔记
2014-12-12 16:51
267 查看
C#有很多特性,但是平常工作的时候用到的机会不多,今天有空试着用了一下,写了段代码,里面用到了索引器、委托、扩展方法、泛型、匿名类型、匿名方法、对象集合初始化器,顿时感觉很高端有木有~~~
public class User { public int UserID { get; set; } public string UserName { get; set; } public int Age { get; set; } } public class MyList<T> { private T[] data; public MyList() { data = new T[0]; } public int Count { get { return data.Length; } } public void Add(T t) { T[] temp = data; data = new T[temp.Length + 1]; temp.CopyTo(data, 0); data[data.Length - 1] = t; } public T this[int index] { get { return data[index]; } set { data[index] = value; } } } public static class Schema { public delegate bool Condtion<T>(T t); public static MyList<T> Search<T>(this MyList<T> myList, Condtion<T> condtion) { MyList<T> result = new MyList<T>(); for (int i = 0; i < myList.Count; i++) { if (condtion(myList[i])) { result.Add(myList[i]); } } return result; } } class Program { static void Main(string[] args) { MyList<User> us = new MyList<User>(); for (int i = 1; i <= 100; i++) { us.Add(new User() { UserID = i, UserName = "name" + i, Age = i }); } var result = us.Search<User>(delegate(User u) { return u.Age > 80; }); Console.ReadLine(); } }
相关文章推荐
- C#学习笔记(四)
- “C#学习笔记”全面改版,欢迎大家访问!
- c#学习笔记
- C#学习笔记一--C#中的参数传递
- C#学习笔记一--C#中的参数传递
- C#中使用Property Grid 控件 学习笔记(一)
- C# Programming Language 学习笔记(六)
- C#学习笔记(七)
- C#学习笔记(六)
- [CSharp]C#2.0 锐利体验系列课程 (1):泛型编程-学习笔记
- "HOW TO: Create a Smooth Progress Bar in Visual C# .NET"的学习笔记
- The Key of C# 学习笔记(你今天学到了什么2004-10)
- [学习笔记]学C#遇到的几个问题
- C#技术内幕 学习笔记
- 《Web Service 编程 --用C#.NET 开发网络服务》北京希望出版社 我的学习笔记(第一章)(也就是书上抄了一写东西而已)
- C#设计模式学习笔记---简单工厂模式
- 不能空着,发篇以前的C++学习笔记,不过现在在学C#
- The key of C# 学习笔记I-II
- 2310学习笔记(二)--C#基础
- C# Programming Language 学习笔记(一)