如何使用C#从列表中删除最后10个元素?
private List<FeedTextDto> _feedsItemGlobal;
public class FeedTextDto
{
public FeedTextDto()
{
Content = new List<ContentDto>();
}
public int Id { get; set; }
public string Title { get; set; }
public string Text { get; set; }
public TextType TextType { get; set; }
public bool IsActive { get; set; }
public DateTime CreatedOn { get; set; }
public string CreatedBy { get; set; }
public List<ContentDto> Content { get; set; }
}
答案 0 :(得分:2)
试试这个:
if(Content.Count >= 10)
Content.RemoveRange(Content.Count - 10, 10);
else
Content.Clear()