-1
class MasterList
{
public int ID = int.MinValue;
public DateTime LastUpdated = DateTime.MinValue;
public MasterList(String sId, String sLastUpdated)
{
sId = ("" + sId).Trim();
sLastUpdated = ("" + sLastUpdated).Trim();
if (sId != "" && sLastUpdated != "")
{
ID = Convert.ToInt32(sId);
LastUpdated = Convert.ToDateTime(sLastUpdated);
}
}
}
List<MasterList> MostUpdatedListFromDataProvider;
List<MasterList> LocalDBList;
如何找到兩個單獨列表中要添加的ID和要更新的ID。需要兩個單獨的清單1.添加新產品2.更新產品。什麼是比較兩個列表的最佳方式<Custom>
我試過這個獲取IDsToUpdate。
public static List<int> IDsToUpdate(List<MasterList> DDF, List<MasterList> DB)
{
List<int> IDs = new List<int>();
foreach (MasterList ml in DDF)
{
MasterList q = (from dbb in DB
where dbb.ID.Equals(ml.ID)
where dbb.LastUpdated < ml.LastUpdated
select dbb).SingleOrDefault();
if (q != null)
{
Console.WriteLine("IDsToUpdate: " + ml.ID);
IDs.Add(ml.ID);
}
}
return IDs;
}
但這是超級慢。
什麼是_purpose_這個:'(「」+ sId).Trim();' – 2014-08-28 23:07:27
正確地修剪輸入字符串,因爲輸入數據有很多變化。 – Amit 2014-08-28 23:12:04
@ Selman22我懷疑它是'!string.IsNullOrEmpty(sId)' – barrick 2014-08-28 23:14:49