C#中List的Find方法的使用
来源:互联网 发布:相片编辑软件下载 编辑:程序博客网 时间:2024/05/28 23:20
查找List中的某个值,可以使用循环遍历对比,查找出结果。C#中提供了Find方法,可以直接使用,只要查找条件传入就可。如下:
class Program { public static void Main(string[] args) { List<User> userCollection = new List<User>(); userCollection.Add(new User(1, "testOne")); userCollection.Add(new User(2, "testTwo")); userCollection.Add(new User(3, "testThree")); User resultUser = userCollection.Find( delegate(User user) { //return user.UserID == 0; return user.UserID == 1 && user.UserName.Equals("testOne"); }); Console.WriteLine(resultUser != null ? resultUser.UserID + System.Environment.NewLine + resultUser.UserName : "没有查找到"); Console.ReadLine(); } } public class User { private int userID = 0; private string userName = string.Empty; public int UserID { get { return this.userID; } } public string UserName { get { return this.userName; } } public User(int userID, string userName) { this.userID = userID; this.userName = userName; } }
结果:
dress : http://blog.csdn.net/yysyangyangyangshan/article/details/7770783
0 0
- C#中List的Find方法的使用
- C#中List的Find方法的使用
- C#中List的Find方法的使用
- C# List中Find的使用方法
- C# List<T>中Find的用法
- C#中List.Find 方法详解
- C# Find() 与 FindAll()方法的使用
- C#中For循环和List.Find效率的比较
- List中方法的使用
- List<>中Find的用法
- C# 中 List的好方法
- List里find的使用。
- C#关于List的find的误解
- Python中find()方法的使用
- python中str.find和 in list的区别使用
- C#中collection,list,map的使用
- C#中List<>的排序使用
- C#中使用List<struct>的问题
- 设计模式之外观模式(Facade)
- 设计模式之建造者模式(Builder)
- 设计模式之观察者模式(Observer)
- 设计模式之抽象工厂模式(AbstractFactory)
- 设计模式之状态模式(State)
- C#中List的Find方法的使用
- 设计模式之适配器模式(Adapter)
- 设计模式之备忘录模式(Memento)
- 设计模式之组合模式(Composite)
- 在 Ubuntu 下如何安装 vsftpd FTP?
- 设计模式之迭代器模式(Iterator)
- 计算机视觉·图像处理
- 设计模式之单例模式(Singleton)
- 程序员的十层楼