110,502
社区成员
发帖
与我相关
我的任务
分享
for (int i = 0; i < orgU.Count(); i++)
{
if (!list_.Any(x => x.UserKey == orgU[i].UserKey))
{
//to do
}
}
var list = new List<int>() { 1, 1, 2, 2, 2, 5, 8, 5, 5, 8, 5, 5, 48, 85, 5, 54, 85 };
Dictionary<int,int> dic=new Dictionary<int, int>();
foreach (var i in list)
{
dic[i] = i;
}
var newList = dic.Keys;
foreach (var i in newList)
{
Console.WriteLine(i);
}
List<int> List = new List<int>() { 1, 2, 3, 12, 2, 3 };
List<int> NewList = new List<int>();
//去重
//var NewList = List.Distinct();
//循环去重
foreach (var item in List)
{
if (!NewList.Contains(item))
{
NewList.Add(item);
}
}
public static class ObjectExtensions
{
public static IEnumerable<TSource> DistinctBy<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector)
{
HashSet<TKey> seenKeys = new HashSet<TKey>();
foreach (TSource element in source)
{
if (seenKeys.Add(keySelector(element)))
{
yield return element;
}
}
}
}
/// <summary>
/// 返回题目数据
/// </summary>
[Serializable]
public class QuestionResult
{
/// <summary>
/// 编号
/// </summary>
public long Id { get; set; }
/// <summary>
/// 题目内容
/// </summary>
public string Title { get; set; }
}
list.DistinctBy(e => new { e.Id }).ToList();