0

I have this ArrayList that consist of list of structure and I would like to use the content of the ArrayList as the return type for the function bellow. Can anyone help please.

public struct DeviceSchedules
        {
            public string StartDate;
            public string EndDate;
            public string Interval;
            public string DeviceTimeZone;
            public string GLRID;
            public string TrackUID;
        }

        [WebMethod()]
        public DeviceSchedules theSchedules()
        {
            ArrayList ZoneArray = new ArrayList();
            ZoneArray.Add("PST");
            ZoneArray.Add("MST");
            ZoneArray.Add("CST");
            ZoneArray.Add("EST");

            DeviceSchedules Schedules = new DeviceSchedules();
            ArrayList GroupSchedule = new ArrayList();

            Int16 Zone = 1;
            DateTime Begining = DateTime.Now.AddHours(Zone);
            DateTime End = DateTime.Now.AddHours(Zone);
            //int Zone = 3;
            Int32 TrackID = 9999;
            Int32 ScheduleID = 400;
            int Frequency = 40;
            for (int index = 0; index <= 5; index++)
            {
                Schedules.StartDate = Convert.ToString(Begining);
                Schedules.EndDate = Convert.ToString(End);
                Schedules.Interval = Convert.ToString(Frequency);
                Schedules.DeviceTimeZone = Convert.ToString(ZoneArray[Zone]);
                Schedules.GLRID = Convert.ToString(ScheduleID);
                Schedules.TrackUID = Convert.ToString(TrackID);
                GroupSchedule.Add(Schedules);
            }
            return (GroupSchedule);
        }
2
Contributors
7
Replies
8
Views
9 Years
Discussion Span
Last Post by justapimp
0

you have to declare the function as an array/string. Something like this would be:

public string[] functionName()
{
}

enjoy :)

0

The suggested implementation did not work. I have also tried some other method to read the list and they don't work either.

0

yes the array have the information. I've also test for the size of the array.

0

The correct implementation to the above question is as follow

public struct DeviceSchedules
        {
            public string StartDate;
            public string EndDate;
            public string Interval;
            public string DeviceTimeZone;
            public string GLRID;
            public string TrackUID;
        }

        [WebMethod()]
        public DeviceSchedules[] theSchedules()
        {
            ArrayList ZoneArray = new ArrayList();
            ZoneArray.Add("PST");
            ZoneArray.Add("MST");
            ZoneArray.Add("CST");
            ZoneArray.Add("EST");

            DeviceSchedules Schedules = new DeviceSchedules();
            ArrayList GroupSchedule = new ArrayList();

            Int16 Zone = 1;
            DateTime Begining = DateTime.Now.AddHours(Zone);
            DateTime End = DateTime.Now.AddHours(Zone);
            //int Zone = 3;
            Int32 TrackID = 9999;
            Int32 ScheduleID = 400;
            int Frequency = 40;
            for (int index = 0; index <= 5; index++)
            {
                Schedules.StartDate = Convert.ToString(Begining);
                Schedules.EndDate = Convert.ToString(End);
                Schedules.Interval = Convert.ToString(Frequency);
                Schedules.DeviceTimeZone = Convert.ToString(ZoneArray[Zone]);
                Schedules.GLRID = Convert.ToString(ScheduleID);
                Schedules.TrackUID = Convert.ToString(TrackID);
                GroupSchedule.Add(Schedules);
            }
            return ((DeviceSchedules[])GroupSchedule.ToArray(typeOf(DeviceSchedule)));
        }

This is kind of "?!@#$%%^&*(@"...

0

yeah.. that's odd. but if it works.. however, i am surprised that my solution didn't work for you! I mean, you declared at the start, instead of formatting at the end. Made sense to me.

0

I am still trying to understand why the latter works. I agree with your suggestion and it should have worked; But I guessed there is a special convention about ArrayList we must understand. Information like that doesn't exist in books. I had to dig through the MSDN to get the aforementioned implementation.

This question has already been answered. 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.