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
など、などの助けを
多くの多くのおかげで何かをしたいとすべきです。