Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.
Hi all, please see this major site announcement: https://www.boards.ie/discussion/2058427594/boards-ie-2026

Creating variable names on the fly .NET

  • 22-09-2009 07:30AM
    #1
    Registered Users, Registered Users 2 Posts: 8,731 ✭✭✭


    I am serializing multiple objects into the one xml file but I don't know exactly how many objects I need as I will be looping through and arraylist thus needing to creating variable names on the fly.

    I have based the majority of the working on serializing on the following link

    http://blogs.askquery.com/2007/06/19/how-to-serialize-multiple-objects-in-a-single-xml-file.aspx

    Can anyone help with creating the variable names on the fly like

    var1
    var2 etc

    Thanks


Comments

  • Registered Users, Registered Users 2 Posts: 2,494 ✭✭✭kayos


    You dont need to. If I read your question right you want to get an array of your object type (you only have one type) from the ArrayList so you can serialize it out to XML. In that case all you need is the below

    SerializeME[] objArray = (objArrayList.ToArray(typeof(SerializeME)) as SerializeME[]);
    

    Where objArrayList is the ArrayList you are working with and the SerializeME is your object type.


  • Registered Users, Registered Users 2 Posts: 8,731 ✭✭✭Trampas


    Thanks.

    Will give that a try and revert back

    Worked a treat. Thanks


Advertisement