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();

            try
            {
                //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);
                       arrayIndex++;
                    }
                }

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.