try { DateTime _LastModifiedDateTC ; List<CIPHApprovedPutModel> timeSheetApprovedView = new List<CIPHApprovedPutModel>(); foreach (var Item in timeSheetApprovedView.TimeCards) { if (Item.IsStateFarm == true) { _LastModifiedDateTC = Global.GetTimecardLastModifiedDate(Item.TimeCardID, (int)InvoiceSourceTypes.TimeCard).GetValueOrDefault(); } else { _LastModifiedDateTC = Global.GetTimecardLastModifiedDate(Item.TimeCardID, (int)InvoiceSourceTypes.PerHour).GetValueOrDefault(); } if (Item.LastModifiedDate == _LastModifiedDateTC) { //how to assign values when condition matches } } List<int> StateFarmTimeCardIDs = timeSheetApprovedView.TimeCards.Where(x => x.IsStateFarm)?.Select(x => x.TimeCardID)?.ToList(); List<int> OtherTimeCardIDs = timeSheetApprovedView.TimeCards.Where(x => !x.IsStateFarm)?.Select(x => x.TimeCardID)?.ToList(); int? BaseStateProvinceID = null;