Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to get all elements from a List

I add each day of the current month to a list in a specific format.

        public static List<string> GetMonthDays()
        {
            DateTime startTime = DateTime.Now;
            DateTime startOfMonth = new DateTime(startTime.Year, startTime.Month, 1);
            int daysInMonth = DateTime.DaysInMonth(startTime.Year, startTime.Month);
            List<string> currentMonth = new List<string>();
            //string[] currentMonth = new string[daysInMonth];
            for (int i = 0; i < daysInMonth; ++i) {

                DateTime currentDate = startOfMonth.AddDays(i);
                currentMonth.Add(currentDate.ToString("dddd - dd.MM.yy", 
                CultureInfo.InvariantCulture));
                
                
        }
            return currentMonth;

        }

I am currently calling the method as follows, but I can only call a single index. How can I retrieve all the elements from the list?

            var monthCurrent = new List<string> { GetMonthDays()[0] };
            ws.Cells["A4:A34"].LoadFromArrays(new List<string[]>(new[] { monthCurrent.ToArray() }));

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Why not simply:

ws.Cells["A4:A34"].LoadFromArrays(GetMonthDays().ToArray());
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading