Hi there,

I'm calling a function which reads XML and holds results in this kind of format:

Item 1: Name="", Category="", InstallerURI=""
Item 2: Name="", Category="", InstallerURI=""
etc.

I need some kind of return variable which will be able to hold this data. So far, I have tried:

// Create struct to hold list attributes
    public struct downloadInfo
    {
        public string[] name, catagory, installer;
    }
    // Lists downloads
    public static downloadInfo downloads()
    {
        downloadInfo downloadlist = new downloadInfo;

Which doesn't work.

// Create struct to hold list attributes
    public struct downloadInfo
    {
        public string name, catagory, installer;
    }
    // Lists downloads
    public static downloadInfo downloads()
    {
        downloadInfo downloadlist = new Array (of) downloadInfo;

But no such 'Array of Struct' method exists.

Jagged arrays have to have a defined length. I don't like that.
Now what? How can I return my data to the caller?

Recommended Answers

All 2 Replies

Use your second struct to hold the data. And you are trying to use VB syntax to declare an array. Use:

downloadInfo[] downloadlist = new downloadInfo[size];

where size is the size of the array. If you want a variable size data structure, use List<T>:

List<downloadInfo> downloadlist = new List<downloadInfo>();

Thank you! The List<> thing was just what I was looking for, but unfortunately it doesn't work well as a list of structs, so I reverted back to an array of structs.
I'll have to figure out some way that the data doesn't exceed the array limit, but it's fine for now.

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.