【发布时间】:2014-11-11 09:49:59
【问题描述】:
在 C# 中从列表中删除重复项
我有一个数据阅读器可以从数据库中读取字符串。
我使用 List 来聚合从数据库中读取的字符串,但我在这个字符串中有重复项。
任何人都有一个快速的方法来从 C# 中的通用列表中删除重复项?
List<string> colorList = new List<string>();
public class Lists
{
static void Main()
{
List<string> colorList = new List<string>();
}
}
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
colorList.Add(variableFromDB.ToString());
foreach (string color in colorList)
{
Response.Write(color.ToString().Trim());
}
}
}
【问题讨论】:
-
.Distinct()怎么样