Hi...
I have a fixed size array in my program.....
but in order to make the program memory efficient....
i want to make it an ArrayList...
can someone please explain how to do this.....
i have posted my code below...

class StaticColumn
    {
        public TextBox[] textBoxes = new TextBox[1000];

        public void getDetails(XmlNode node)
        {
            XmlElement nodeAsElement = node as XmlElement;
            XmlNodeList _list = nodeAsElement.GetElementsByTagName("Textbox");
            int i=0;
            foreach (XmlNode tempNode in _list)
            {
                textBoxes[i] = new TextBox();
                textBoxes[i].getDetails(tempNode);
                i++;
            }

                                    
        }
    }
class TextBox
    {
        public string name = string.Empty;
        public string value = string.Empty;
        public string visibility = string.Empty;
        public Navigation navigation = new Navigation();

        public void getDetails(XmlNode node)
        {
            XmlElement nodeAsElement = node as XmlElement;

            try { name = node.Attributes["Name"].InnerText.ToString(); }
            catch (NullReferenceException e)            {            }

            try { value = nodeAsElement.GetElementsByTagName("Value")[0].InnerText.ToString(); }
            catch (NullReferenceException e) { }

            try { visibility = nodeAsElement.GetElementsByTagName("Visibility")[0].InnerText.ToString(); }
            catch (NullReferenceException e) { }

            try { visibility = nodeAsElement.GetElementsByTagName("Hidden")[0].InnerText.ToString(); }
            catch (NullReferenceException e) { }

            try
            {
                navigation = new Navigation();
                node = nodeAsElement.GetElementsByTagName("Drillthrough")[0];
                navigation.getDetails(node);
            }
            catch (NullReferenceException e) { navigation = null; }
            
        }

        public void getElements(XmlNode node)
        {
            XmlElement nodeAsElement = node as XmlElement;

            try { name = node.Attributes["Name"].InnerText.ToString(); }
            catch (NullReferenceException e) { }

            try { visibility = nodeAsElement.GetElementsByTagName("Visibility")[0].FirstChild.InnerText.ToString(); }
            catch (NullReferenceException e) { }

            //try { visibility = nodeAsElement.GetElementsByTagName("Hidden")[0].InnerText.ToString(); }
            //catch (NullReferenceException e) { }

            try
            {
                navigation = new Navigation();
                node = nodeAsElement.GetElementsByTagName("Drillthrough")[0];
                navigation.getDetails(node);
            }
            catch (NullReferenceException e) { navigation = null; }

            try
            {
                nodeAsElement = (XmlElement)nodeAsElement.GetElementsByTagName("Paragraphs")[0];
                XmlNodeList _list1 = nodeAsElement.GetElementsByTagName("Value");
                foreach (XmlNode tempNode in _list1)
                {
                    value = value + tempNode.InnerText.ToString();
                }
            }
            catch (NullReferenceException e) { }
        }

    }

i also want to know how to read from the new class .. Because i'm sure the changes would also affect the reading...

Recommended Answers

All 6 Replies

check these link may be helpful 1st link.... 2nd link

hi...
i have already seen these links....
what i need is to create array list of custom classes.....
thanks anyways....

check these link may be helpful 1st link.... 2nd link

what i mean is i need a more detailed explanation.....
the explanation given there is quite simple and it is for a simple list....
i want to know how to do it wen i am doing it with a custom class with lots of variables...
like the example i posted.....

Have you checked this one? and this one....and this.... actually I ddn't understand you question so giving you these links that might be helpful in understanding the core of arraylist

what i am asking is......
if i have to make :-

public TextBox[] textBoxes = new TextBox[1000];

AS

public List<TextBox> textBoxes = new List<TextBox>();

what are the changes i'll have to make to the textbox class to read and write data.....

I have found a solution....
All i have to do is this...

class StaticColumn
    {
        public System.Collections.ArrayList textBoxes = new System.Collection.ArrayList();

        public void getDetails(XmlNode node)
        {
            XmlElement nodeAsElement = node as XmlElement;
            XmlNodeList _list = nodeAsElement.GetElementsByTagName("Textbox");
            int i=0;
            foreach (XmlNode tempNode in _list)
            {
                TextBox t = new TextBox();
                t.getDetails(tempNode);
                textBoxes.Add(t);
            }

                                    
        }
    }
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.