//这是 List<T>.Find(Predicate<T> predicate) 的源代码。
public T Find(Predicate<T> match)
{
if (match == null)
{
ThrowHelper.ThrowArgumentNullException(ExceptionArgument.match);
}
for (int i = 0; i < this._size; i++)
{
if (match(this._items[i]))
{
return this._items[i];
}
}
return default(T);
}
//以下是我做项目中的一个方法
/// <summary>
/// 根据评论编号获取评论信息
/// </summary>
/// <param name="commentID">评论编号</param>
/// <returns></returns>
public Comment GetCommentByID(int commentID)
{
return commentList.Find((com) => com.CommentID == commentID);
}
/// <summary>
/// 根据编号获取所有评论信息
/// </summary>
/// <param name="commentID">评论编号</param>
/// <returns></returns>
public List<Comment> GetCommentListByI
在List(T)中查找数据的两种方法
最新推荐文章于 2024-06-18 10:04:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)