Hi, as explained in the title I'm having a problem storing data to an array of IEnumerables: The source code is as follows:-

internal static IEnumerable<ReportDriverMovements> CreateReportDriverMovements(IEnumerable<DataScansTran> iEnumDST
            List<ReportDriverMovements> iEnumReportDriverMovements = new List<ReportDriverMovements>();
            st2DataContext dc = new st2DataContext();

                //Get lists of individual driver movements by site and in/out
                DateTime? nullDateTime = null;
                IEnumerable<String> iEnumDrivers = (from dm in iEnumDST select dm.description).Distinct();
                IEnumerable<String> iEnumSites = (from dm in iEnumDST select dm.Site.name).Distinct();
                IEnumerable<DataScansTran>[] driverSiteMovementsIn = new IEnumerable<DataScansTran>[iEnumSites.Count() * iEnumDrivers.Count()];
                IEnumerable<DataScansTran>[] driverSiteMovementsOut = new IEnumerable<DataScansTran> [iEnumSites.Count() * iEnumDrivers.Count()];

                int arrayIndex = 0;

                foreach (String driver in iEnumDrivers)
                    foreach (String site in iEnumSites)
                       driverSiteMovementsIn[arrayIndex] = iEnumDST.Where(dst => dst.description == driver &&
                                                                                 dst.Site.name == site &&
                                                                                 dst.transactionType == 5).OrderBy(dst => dst.createDate);                       

                       driverSiteMovementsOut[arrayIndex] = iEnumDST.Where(dst => dst.description == driver &&
                                                                                  dst.Site.name == site &&
                                                                                  dst.transactionType == 6).OrderBy(dst => dst.createDate);

The arrays I'me referring to are driverSiteMovementsIn and driverSiteMovementsOut. When I step through the code the data is shown as being stored correctly in each array element. However once the array population process is complete - the arrays are empty. Is this because Ienumerable is an Interface and therefore abstract ??

Press the Toggle Plain Text link above the source code to view the code properly formatted.

Many Thanks

Edited by C#Jonathan: n/a

6 Years
Discussion Span
Last Post by Momerath

Them being interfaces has nothing to do with it. It's because of the way IEnumerables work and I'm not sure how I can explain it :) Change your arrays to List<> arrays and it should solve your problem. You'll probably have to add ToList() to the end of the LINQ statements.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.