my apologize if you do not understand this, as im am very tired as i type.

i am trying to make an Array of "EventItem"'s
i do not know the size i need the array to be so i needed a way to add them which is why i used a arraylist.

but i need to work with the data in the array which means converting out of the arraylist to the object(EventItem) each time i want to use the data. fustrating

so, my solution to which i need help is getting rid of that class which is only an arraylist, and using an indexer for my struct

i just dont understand how the indexers work, ive looked up info but how is it different then just making an array?

please help me understand indexers with the following code :cry:

using System;
using System.Collections;
using System.Data;

namespace skControls
{

	public struct EventItem
	{


		public DateTime eventDate;
		public string eventInfo;
		public string eventName;
		public string eventType;


		public EventItem(DateTime dt, string name , string info, string type)
		{
			eventDate = dt;
			eventName = name;
			eventInfo = info;
			eventType = type;
			
		}


	}
	

	public class DayEvents
	{

		public ArrayList EventList;

		public DayEvents()
		{
			EventList = new ArrayList();

		}

		public void AddEvent(DateTime dt, string name , string info, string type)
		{
			EventList.Add(new EventItem(dt,name,info,type));
		}

		public int EventCount()
		{
			return EventList.Count;
		}

After i took a break and drank some coffee i found a fixed my problem
heres what i did, if you have and suggestions please give them. thx

public struct EventItem
	{


		public DateTime eventDate;
		public string eventInfo;
		public string eventName;
		public string eventType;


		public EventItem(DateTime dt, string name , string info, string type)
		{
			eventDate = dt;
			eventName = name;
			eventInfo = info;
			eventType = type;
			
		}

		public override string ToString()
		{
			return eventDate.ToShortDateString() + " " +
					eventName + " " + eventInfo + " " + eventType;
		}




	}

	public class DayEvents
	{
		private EventItem[] data;
		public DayEvents()
		{
			data = new EventItem[1];
		}

		private void IncreaseSize()
		{
			EventItem[] temp = data;
			data = new EventItem[temp.Length +1];
			Array.Copy(temp,data,temp.Length);
			temp = null;
		}

		public EventItem this[int index]
		{
			get
			{
				return data[index];					
			}
			set
			{
				if(index >= data.Length)
				{
					IncreaseSize();
				}
				data[index] = value;
			}
		}
	}
This article has been dead for over six months. Start a new discussion instead.