举例如下:
List<Plan.AdmissionPlanModelNew> list_new = new List<Plan.AdmissionPlanModelNew>();
List<Plan.AdmissionPlanModelNew> list_sort = new List<Plan.AdmissionPlanModelNew>();
1、AddRange集合的元素添加到指定集合中
list_new .AddRange(list_sort);
2、分页使用
int Star = (Page - 1) * PageSize;
int End = Page * PageSize;
int Count = list_sort.Count - Star;
if (Count < PageSize)
{
list_new = list_sort.GetRange(Star, Count);
}
else if (Count >= PageSize)
{
list_new = list_sort.GetRange(Star, PageSize);
}
3、排序使用
public class AdmissionPlanModelNew : IComparable<AdmissionPlanModelNew>
{
private double _probability = 0;
/// <summary>
/// 概率值
/// </summary>
public double Probability
{
get { return _probability; }
set { _probability = value; }
}
public int CompareTo(AdmissionPlanModelNew obj)
{
if (this.Probability > obj.Probability)
return 1;
else
return -1;
}
}
使用方法:
list_sort.Sort((x, y) => { return -x.Probability.CompareTo(y.Probability); });
4.List赋值
public class NoteTime
{
/// <summary>
/// 当前周几数字
/// </summary>
public int Week { set; get; }
/// <summary>
/// 一年中当前周几的全部日期
/// </summary>
public List<TimeStr> Content { set; get; }
}
public class TimeStr
{
/// <summary>
/// 当前周几的日期
/// </summary>
public string Time { set; get; }
}
使用方法:
//week不能重复,Content保存日期集合
if (i.DayOfWeek == DayOfWeek.Monday)
{
if (!list.Exists(t => t == 1))
{
list.Add(1);
}
if (TimeList.Exists(t => t.Week == 1))//判断当前周一在集合中是否存在
{
int index = list.IndexOf(1);
NoiteBook.TimeStr time_con = new NoiteBook.TimeStr();
time_con.Time = i.ToString("yyyy-MM-dd");
TimeList[index].Content.Add(time_con);
}
else //不存在,进行首次赋值操作
{
week_con.Week = 1;
///Content内容重新声明,进行赋值
List<NoiteBook.TimeStr> timelist = new List<NoiteBook.TimeStr>();
NoiteBook.TimeStr time_con = new NoiteBook.TimeStr();
time_con.Time = i.ToString("yyyy-MM-dd");
timelist.Add(time_con);
week_con.Content = timelist;
}
}
4、判断是否在List数组中存在当前元素值
/// <summary>
/// CollectApiModel 的摘要说明
/// </summary>
[DataContract]
public class CollectApiModel
{
/// <summary>
/// 收藏ID
/// </summary>
[DataMember]
public int Time ;
}
//判断几个中是否存在相同日期的演出数据
if (List.Exists(t => t.Time == DateTime.Parse(data.Tables[0].Rows[i]["PerformTime"].ToString()).ToString("yyyy-M-d")))
{
//获取相等数据,在集合中下标值
int index = List.FindIndex(t => t.Time == DateTime.Parse(data.Tables[0].Rows[i]["PerformTime"].ToString()).ToString("yyyy-M-d"));
List[index].SeatsTotal += Int32.Parse(data.Tables[0].Rows[i]["SeatsTotal"].ToString());
List[index].OrderSeatsNumber += Int32.Parse(data.Tables[0].Rows[i]["OrderSeatsNumber"].ToString());
}
仅供个人笔记使用,不喜勿喷!!!!!