邢俊杰吧 关注:8贴子:198
  • 2回复贴,共1

关于List<>的学习笔记

只看楼主收藏回复

mList为列表List<MaterialInfo>,MaterialInfo为带ID成员的结构
可按下面两种方法改变列表的部分结构成员
for (int i = 0; i < mList.Count; i++)
{
if (mList[i].TID == oID)
{
MaterialInfo tmpInfo = mList[i];
tmpInfo.TID = nType.ID;
tmpInfo.ID = (nType.ID - mList[i].TID) * 1000 + mList[i].ID;
mList[i] = tmpInfo;
}
}
或者
while ((index = mList.FindIndex(mInfo => mInfo.TID == oID)) >= 0)
{
MaterialInfo tmpInfo = mList[index];
tmpInfo.TID = nType.ID;
tmpInfo.ID = (nType.ID - mList[index].TID) * 1000 + mList[index].ID;
mList[index] = tmpInfo;
}


IP属地:河南1楼2015-11-28 14:46回复
    List<>.Sort()用法:
    tList.Sort((x, y) => x.ID < y.ID ? -1 : 0);
    或者
    var v = from t in tList orderby t.ID select t;
    tList = v.ToList();


    IP属地:河南2楼2015-11-28 14:50
    回复
      2026-05-30 04:18:59
      广告
      不感兴趣
      开通SVIP免广告
      IP属地:河南3楼2015-11-28 14:52
      回复