码迷,mamicode.com
首页 > 其他好文 > 详细

只用一次循环开销 将类似 1 A 、1 B 的数据返回成为 1 A,B 的拼接形式

时间:2015-02-26 09:45:02      阅读:125      评论:0      收藏:0      [点我收藏+]

标签:

     /// <summary>
     ///
将类似 1 A 、1 B 的数据返回成为 1 A,B 的拼接形式 /// </summary> /// <param name="list"></param> /// <returns></returns> private BookingInShopListDataContract[] GenDistinctList(List<BookingInShopListDataContract> list) { //定义实际要返回到界面的aimList List<BookingInShopListDataContract> aimList = new List<BookingInShopListDataContract>(); string bookingNo = string.Empty; string repairType = string.Empty; BookingInShopListDataContract cloneDC = new BookingInShopListDataContract(); BookingInShopListDataContract addDC = null; if (list.Count == 0) { return aimList.ToArray(); } foreach (var item in list) { if (string.IsNullOrEmpty(bookingNo)) { bookingNo = item.BookingNo; repairType = item.RepairTypeName; } else if (bookingNo == item.BookingNo) { if (!string.IsNullOrEmpty(item.RepairTypeName)) { repairType = repairType + "," + item.RepairTypeName; } } else { AddNewCloneDC(addDC, cloneDC, bookingNo, repairType, aimList); cloneDC = new BookingInShopListDataContract(); bookingNo = item.BookingNo; repairType = item.RepairTypeName; } addDC = item; } AddNewCloneDC(addDC, cloneDC, bookingNo, repairType, aimList); return aimList.ToArray(); } private void AddNewCloneDC(BookingInShopListDataContract aAddDC, BookingInShopListDataContract aCloneDC, string aBookingNo, string aRepairType, List<BookingInShopListDataContract> aAimList) { aCloneDC.BookingNo = aBookingNo; aCloneDC.BookingStatus = aAddDC.BookingStatus; aCloneDC.OwnerName = aAddDC.OwnerName; aCloneDC.OwnerPhone = aAddDC.OwnerPhone; aCloneDC.CarLicenseNo = aAddDC.CarLicenseNo; aCloneDC.FrameNo = aAddDC.FrameNo; aCloneDC.BookComeTime = aAddDC.BookComeTime; aCloneDC.BookEndTime = aAddDC.BookEndTime; aCloneDC.Receiver = aAddDC.Receiver; aCloneDC.ReceiverName = aAddDC.ReceiverName; aCloneDC.OpertatorName = aAddDC.OpertatorName; aCloneDC.RepairTypeName = aRepairType; aCloneDC.SolicitType = aAddDC.SolicitType; aAimList.Add(aCloneDC); }

 

只用一次循环开销 将类似 1 A 、1 B 的数据返回成为 1 A,B 的拼接形式

标签:

原文地址:http://www.cnblogs.com/ShaYeBlog/p/4300516.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!