1
需要一些幫助,我的foreach重新獲得空記錄並用「 - 」填補空缺。c#填寫空記錄
讓我們說我們的情況下30分鐘,45分鐘,90分鐘,120分鐘,而不是60分鐘:
它可以指望每個ID的總記錄,讓我們說最大的是5,30分鐘,45分鐘,60分鐘,90分鐘和120分鐘。
如果有3個,那麼它可以檢查哪個丟失,並且可以填充「 - 」。
腳本的意思是一樣的。
List<Treatment> treatment = new List<Treatment>();
treatment.Add(new Treatment { id = 1, treatmentNameId = 11, duration = "30", price = 30 });
treatment.Add(new Treatment { id = 1, treatmentNameId = 11, duration = "45", price = 45 });
treatment.Add(new Treatment { id = 1, treatmentNameId = 11, duration = "60", price = 60 });
treatment.Add(new Treatment { id = 1, treatmentNameId = 2, duration = "30", price = 30 });
//treatment.Add(new Treatment { id = 1, treatmentNameId = 2, duration = "45", price = 45 });
treatment.Add(new Treatment { id = 1, treatmentNameId = 2, duration = "60", price = 60 });
var newList = (from t in treatment
select t)
.AsQueryable().ToList();
List<List> newList= new List<List>();
foreach (var item in newList)
{
if (item.duration == "30")
{
newList.Add(new List { treatmentNameId = item.treatmentNameId, thirtyMin = "30" });
}
if (item.duration == "45")
{
newList.Add(new List { treatmentNameId = item.treatmentNameId, fortyFive= "45" });
}
if (item.duration == "60")
{
newList.Add(new List { treatmentNameId = item.treatmentNameId, sixty= "60" });
}
}
最終結果應該喜歡的東西作爲,
id:1 30, 45, 60, -
id:2 30, - , 60, 90
id:3 - , 45, -, 90
等等
很多很多的幫助表示感謝。