Storing data in an array
-
I have been looking at http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx trying to figure this out but I just seem to get it. I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data. The only way I can think to explain it is more like XML. One function will return different items from a XML feed, and the other will return one record from an XML feed with the information Example for multiple records:
[Message]
[ID]44562[/ID]
[/Message]
[Message]
[ID]44562[/ID]
[/Message]
[Message]
[ID]44562[/ID]
[/Message]Example for single records:
[Message]
[ID]44562[/ID]
[From]Scott[/From]
[To]Scott[/To]
[Subject]Test[/Subject]
[/Message] -
I have been looking at http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx trying to figure this out but I just seem to get it. I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data. The only way I can think to explain it is more like XML. One function will return different items from a XML feed, and the other will return one record from an XML feed with the information Example for multiple records:
[Message]
[ID]44562[/ID]
[/Message]
[Message]
[ID]44562[/ID]
[/Message]
[Message]
[ID]44562[/ID]
[/Message]Example for single records:
[Message]
[ID]44562[/ID]
[From]Scott[/From]
[To]Scott[/To]
[Subject]Test[/Subject]
[/Message]Brad Wick wrote:
I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data.
If you can't figure out how to add data to an array then I suggest you get a beginners book. Look for book reviews here on the site.
led mike
-
Brad Wick wrote:
I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data.
If you can't figure out how to add data to an array then I suggest you get a beginners book. Look for book reviews here on the site.
led mike
Adding items to an array I can do, but not a Multidimensional Array. Some people do not read books, but search the internet and learn from each time they tackle something. I have been playing around in C# for some time and can do pretty much anything that is needed, but trying to learn some other items. Why dont you just respond to every post "go buy a book" that is so much more helpful then actually helping someone out.
-
I have been looking at http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx trying to figure this out but I just seem to get it. I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data. The only way I can think to explain it is more like XML. One function will return different items from a XML feed, and the other will return one record from an XML feed with the information Example for multiple records:
[Message]
[ID]44562[/ID]
[/Message]
[Message]
[ID]44562[/ID]
[/Message]
[Message]
[ID]44562[/ID]
[/Message]Example for single records:
[Message]
[ID]44562[/ID]
[From]Scott[/From]
[To]Scott[/To]
[Subject]Test[/Subject]
[/Message]Just look at your XML examples (hierarchy). It's just a name/value pair array.
-
Adding items to an array I can do, but not a Multidimensional Array. Some people do not read books, but search the internet and learn from each time they tackle something. I have been playing around in C# for some time and can do pretty much anything that is needed, but trying to learn some other items. Why dont you just respond to every post "go buy a book" that is so much more helpful then actually helping someone out.
-
Just look at your XML examples (hierarchy). It's just a name/value pair array.
-
So you think it would be better to store the information in XML to pass between different functions/objects?
No. I don't know your application so it's hard to say what's better. What I was getting at was that if you're confused about multi-dimensional arrays, just look at your XML to visualize what it would look like. In 2.0 forward, you could use a generic list, but I think you said you're using 1.0+ [Edit] No, the 1.0 was from another question. Sorry.
-
I have been looking at http://msdn.microsoft.com/en-us/library/aa288453(VS.71).aspx trying to figure this out but I just seem to get it. I have a function that I would like it to return the information in an array or something like it, but I can't figure out how to add the data. The only way I can think to explain it is more like XML. One function will return different items from a XML feed, and the other will return one record from an XML feed with the information Example for multiple records:
[Message]
[ID]44562[/ID]
[/Message]
[Message]
[ID]44562[/ID]
[/Message]
[Message]
[ID]44562[/ID]
[/Message]Example for single records:
[Message]
[ID]44562[/ID]
[From]Scott[/From]
[To]Scott[/To]
[Subject]Test[/Subject]
[/Message]The way I normally handle this is to create a class (or struct if more appropriate) for a single item, then create a class that is a generic list of single items. e.g.
public class MyMessage
{
// variables, properties, methods, constructors etc...
}using System.Collections.Generic;
public class MyMessageCollection : List<MyMessage>
{
// returns the message with specified ID or new empty message if not found
public MyMessage FindItemFromID(int id)
{
MyMessage found = this.Find(c => c.ID == id);
return found != null ? found : new MyMessage();
}// other methods (loading, saving...) etc...
}Dave