It is the IEnumerable interface that enables support for the foreach construct. IOW, You can use foreach to iterate within your MainObj only if it has implemented the IEnumerable interface.
On Dec 16, 4:59 pm, raddars <[email protected]> wrote: > Hi all, > Is it possible to loop through an object and put each element into an > array? > > I have the following code breaks on the foreach because of > GetEnumerator not being a public definition. Not sure how to correct > it or what that means! > Many thanks, > > try > { > XmlSerializer deserializer = new XmlSerializer(typeof > (Main)); > textReader = new StreamReader > (System.AppDomain.CurrentDomain.BaseDirectory + "test.xml", true); > mainObj = (Main)deserializer.Deserialize > (textReader); > foreach(object o in mainObj) { > myArraylist.Add(o); > } > }
